-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path92059186.cpp
72 lines (72 loc) · 1.17 KB
/
92059186.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
using namespace std;
void func()
{
int n,k;
cin>>n>>k;
char str[n];
char alaki;
scanf("%c",&alaki);
for(int i=0;i<n;i++)
scanf("%c",&str[i]);
bool ok=true;
for(int i=0;i+k<n;i++)
{
int j=i+k;
if(str[i]==str[j])
continue;
if(str[i]=='?')
{
str[i]=str[j];
}
else
{
if(str[j]!='?')
{
//cout<<"problem in i "<<i<<endl;
ok=false;
break;
}
else
str[j]=str[i];
}
}
// for(int i=0;i<n;i++)
// cout<<str[i];
// cout<<endl;
int zero=0;
int one=0;
int none=0;
for(int i=0;i<k;i++)
{
if(str[i]=='0')zero++;
else if(str[i]=='1')one++;
else none++;
}
//cout<<zero<<" "<<one<<" "<<none<<endl;
if(abs(zero-one)>none)
ok=false;
for(int i=k;i<n;i++)
{
if(str[i]=='0')zero++;
else if(str[i]=='1')one++;
else none++;
if(str[i-k]=='0')zero--;
else if(str[i-k]=='1')one--;
else none--;
if(abs(zero-one)>none)
ok=false;
}
if(ok)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
func();
return 0;
}