forked from sastava007/Tech-Interview-Preparation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled4.cpp
More file actions
46 lines (44 loc) · 1.07 KB
/
Untitled4.cpp
File metadata and controls
46 lines (44 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
#include "bits/stdc++.h"
#define sync ios_base::sync_with_stdio(0)
#define ll unsigned long long
#define all(a) a.begin(), a.end()
#define vi vector<int>
#define vll vector<long long>
using namespace std;
int main() {
sync;
ll t;
cin >> t;
while(t--) {
string s;
cin >> s;
int n = s.size();
ll answer = 0;
int ones = count(all(s), '1');
int zeros = count(all(s), '0');
for(int i = 0; i < n-1; i++) {
int t0 = 0, t1 = 0;
if(s[i] == '1') {
t1++;
}
else {
t0++;
}
for(int j = i+1; j < n; j++) {
if(s[j] == '1') {
t1++;
if(t1 * t1 > zeros) break;
}
else {
t0++;
if(ones * ones < t0) break;
}
if(t1 * t1 == t0) answer++;
}
if(s[i] == '1') ones--;
else zeros--;
}
cout << answer << endl;
}
return 0;
}