-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Balanced_Bitstring.cpp
More file actions
62 lines (52 loc) · 1.07 KB
/
A_Balanced_Bitstring.cpp
File metadata and controls
62 lines (52 loc) · 1.07 KB
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline void n_lamba_29() {
int n, k;
string s;
cin >> n >> k >> s;
int i = 0, j = k;
while(j < n) {
if(s[i] != '?' && s[j] != '?' && s[i] != s[j]) {
cout << "NO\n";
return;
}
if(s[i] == '?') s[i] = s[j];
if(s[j] == '?') s[j] = s[i];
i++;
j++;
}
int t1 = 0, t2 = 0;
for(int i=0;i<k;i++) {
if(s[i] == '1') t1++;
else if(s[i] == '0') t2++;
}
if(t1 > k/2 || t2 > k/2) {
cout << "NO\n";
return;
}
i = 0, j = k;
while(j < n) {
if(s[i] == '1') t1--;
else if(s[i] == '0') t2--;
i++;
if(s[j] == '1') t1++;
else if(s[j] == '0') t2++;
j++;
if(t1 > k/2 || t2 > k/2) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int32_t main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int _;
cin >> _;
while (_-->0) {
n_lamba_29();
}
return 0;
}