Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include <iostream>
using namespace std;
int main() {
// your code goes here
int tests;
cin>>tests;
while(tests--){
int n;
cin>>n;
int cur=0, largest=0, sec_largest=0, in;
for(int i=0;i<n;i++){
cin>>in;
if(in == 0){
cur++;
}
else{
if(cur>largest){
sec_largest = largest;
largest = cur;
}
else if(cur>sec_largest){
sec_largest = cur;
}
cur = 0;
}
}
if(largest%2==1 && sec_largest<(largest+1)/2)
cout<<"Yes\n";
else
cout<<"No\n";
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int maxlen=0,sec_max=0,len;
for(int i=1;i<n;i++)
{
if(arr[i]==0)
{
len=0;
while(arr[i]==0)
{
len++;
i++;
}
if(len>maxlen)
{sec_max=maxlen;
maxlen=len;}
else if(len>sec_max)
sec_max=len;
}
}
if(maxlen%2==0)
{
cout<<"No"<<endl;
continue;
}
else{
if(sec_max<(maxlen+1)/2)
{
cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
}
}
return 0;
}
# cook your dish here
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
zs = []
zeros = 0
for i in a:
if i==1:
zs.append(zeros)
zeros = 0
elif i==0: zeros+=1
zs.append(zeros)
#print(zs)
zs.sort()
b = zs[-1]
if b%2==0: print("No")
elif b%2==1:
if len(zs)==1: print("Yes")
else:
nnum = b//2+1
tnum = max(b//2,zs[-2])
if nnum>tnum: print("Yes")
else: print("No")
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define lli long long int
#define li long int
#define inf 10000
int max(int a, int b)
{
int m = a;
if(b>a)
m = b;
return m;
}
int min(int a, int b)
{
int m = a;
if(b<a)
m = b;
return m;
}
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(lli arr[], lli l, lli m, lli r)
{
lli i, j, k;
lli n1 = m - l + 1;
lli n2 = r - m;
/* create temp arrays */
lli L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
}
else if(L[i]> R[j]) {
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(lli arr[], lli l, lli r)
{
if (l < r) {
// Same as (l+r)/2, but avoids overflow for
// large l and h
lli m = l + (r - l) / 2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
/* //players are A and B
1. Find all zero-strips
2. Sort acnn to their length
3. if A choose any postion of any samller strip, B will choose The corner of larger strip and win
4. A always choose the Longest strip
5. If longest stip is even then, irresopective of chosen position of A, B wins alwayas.
6. if its odd then A must choose middle position to be optimal.
7. Now if B choose its side then he must loose
8. So he goes for corner of other strip
9. if find that he will win.
*/
void program()
{
lli n;
scanf("%lld", &n);
lli A[n];
lli i;
for ( i = 0; i < n; i++)
{
scanf("%lld", &A[i]);
}
lli ZeroStrips[n];
lli j = 0;
for ( j = 0; j < n; j++)
{
ZeroStrips[j] = 0;
}
j = 0;
for ( i = 0; i < n; i++)
{
if(A[i] == 0)
{
ZeroStrips[j]++;
continue;
}
j++;
if(A[i] == 1)
continue;
}
lli zersarrlen = j;
/*for ( i = 0; i < zersarrlen; i++)
{
printf("%lld ", ZeroStrips[i]);
}*/
mergeSort(ZeroStrips, 0, zersarrlen-1);
if(ZeroStrips[zersarrlen-1]%2 == 0)
{
printf("No\n");
}
else
{
lli maxlen = ZeroStrips[zersarrlen-1];
lli scemax = ZeroStrips[zersarrlen-2];
lli aftermax = maxlen/2;
if(scemax > aftermax)
{
printf("No\n");
}
else
{
printf("Yes\n");
}
}
}
int main(void)
{
long long int T;
scanf("%lld", &T);
//printf("%lld\n", T);
// T = 1;
for (long long int i = 0; i < T; i++)
{
program();
}
return 0;
}
import java.util.*;
import java.io.*;
public class Main{
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args) {
try {
FastReader in=new FastReader();
FastWriter out = new FastWriter();
int testCases=in.nextInt();
while(testCases-- > 0){
int n = in.nextInt();
int arr[] = new int[n];
int count = 0, sec = 0,temp = 0;
for(int i = 0; i<n ; i++){
arr[i] = in.nextInt();
if(arr[i] == 0){
temp++;
}else{
if(temp>count){
sec = count;
count= temp;
}else if(temp >sec){
sec = temp;
}
temp = 0;
}
}
if((count&1)==1 && count/2+1>sec)out.println("Yes");
else out.println("No");
}
out.close();
} catch (Exception e) {
return;
}
}
}
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
Z = [0]*n
j = 0
for i in l:
if(i == 0):
Z[j] += 1
else:
j += 1
# print(Z)
Z.sort(reverse = True)
first, second = Z[0], Z[1]
if first % 2 == 0:
print("No")
else:
if first//2 < second:
print("No")
else:
print("Yes")
from collections import defaultdict
t=int(input())
for i in range(t):
n=int(input())
a=raw_input().split()
a="".join(a)
a= a.split('1')
a.sort(reverse=True)
#print a
if(len(a[0])%2==0):
print 'No'
else:
if(len(a)>1 and len(a[1])>=(len(a[0])/2+1)):
print 'No'
else:
print 'Yes'
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
tc := readNum(reader)
for tc > 0 {
tc--
n := readNum(reader)
A := readNNums(reader, n)
res := solve(n, A)
if res {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
}
func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}
func readNum(reader *bufio.Reader) (a int) {
bs, _ := reader.ReadBytes('\n')
readInt(bs, 0, &a)
return
}
func readTwoNums(reader *bufio.Reader) (a int, b int) {
res := readNNums(reader, 2)
a, b = res[0], res[1]
return
}
func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
res := readNNums(reader, 3)
a, b, c = res[0], res[1], res[2]
return
}
func readNNums(reader *bufio.Reader, n int) []int {
res := make([]int, n)
x := 0
bs, _ := reader.ReadBytes('\n')
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
x = readInt(bs, x, &res[i])
}
return res
}
func readUint64(bytes []byte, from int, val *uint64) int {
i := from
var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp
return i
}
func solve(n int, A []int) bool {
var i int
for i < n && A[i] == 0 {
i++
}
// win only if n is odd
if i == n {
return n&1 == 1
}
var first, second = -1, -1
update := func(cur int) {
if cur > first {
first, second = cur, first
} else if cur > second {
second = cur
}
}
if i > 0 {
update(i)
}
for i < n {
//A[i] is 1 here
if i+1 < n && A[i+1] == 0 {
i++
j := i
for j < n && A[j] == 0 {
j++
}
update(j - i)
i = j - 1
}
i++
}
if first < 0 || first&1 == 0 {
return false
}
if second < 0 {
return first&1 == 1
}
return second <= first/2
}
In our experience, we suggest you solve this Game on a Strip CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Game on a Strip CodeChef Solution.
I hope this Game on a Strip CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.
Keep Learning!