-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbalancedbitstring1500.cpp
More file actions
39 lines (37 loc) · 924 Bytes
/
balancedbitstring1500.cpp
File metadata and controls
39 lines (37 loc) · 924 Bytes
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
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
int main(){
int t;
cin >> t;
while(t--){
int n,k;
cin >> n >> k;
string s;
cin >> s;
bool flag = true;
int zero = 0,one = 0,question = 0;
int l = 0;
for(int r = 0; r < n; r++){
if(s[r] == '0') zero++;
else if(s[r] == '1') one++;
else question++;
if(r - l + 1 == k){
int diff = abs(one - zero);
if(question < diff || (question - diff)%2 != 0) flag = false;
if(s[l] == '1') one--;
else if(s[l] == '0') zero--;
else question--;
l++;
}
}
if(flag == true) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}