-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinfinite_pref.cpp
More file actions
executable file
·65 lines (55 loc) · 1.54 KB
/
infinite_pref.cpp
File metadata and controls
executable file
·65 lines (55 loc) · 1.54 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
63
64
65
// g++ infinite_pref.cpp -o infinite_pref && ./infinite_pref
/*
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL)
#define endl '\n'
#define ll long long int
using namespace std;
#define pii pair <ll , ll >
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define loop(x) for (int i = 0; i < x; i++)
int find_bal(string str, int s){
int zer = 0, one = 0;
for (int i = 0; i < s; i++){
if (str[i] == '0') zer++;
else one++;
}
return zer - one;
}
int main(){
// fastio;
int t;
cin >> t;
int s, x;
int bal, ans;
string str;
while (t--) {
cin >> s >> x;
cin >> str;
bal = find_bal(str, s);
if (x == 0){
if (bal == 0) ans = -1;
else 1;
}
else if (bal == 0 || bal < x){
}
else {
ans = 1;
for (int i = 2; i < s; i++) {
for (int j = i; j < s; j += i) {
if (!find_bal(str.substr(0, j-1), i)) ans++;
else break;
}
reverse(str.begin(), str.end());
for (int j = i; j < s; j += i) {
if (!find_bal(str.substr(0, j-1), i)) ans++;
else break;
}
}
}
cout << ans << endl;
}
}