-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoJosIncredibleAdventures.cpp
More file actions
49 lines (46 loc) · 1.1 KB
/
Copy pathJoJosIncredibleAdventures.cpp
File metadata and controls
49 lines (46 loc) · 1.1 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
// https://codeforces.com/problemset/problem/1820/B
#include <bits/stdc++.h>
#define ll long long
#define u32 uint32_t
#define u64 uint64_t
#define i64 int64_t
using namespace std;
void solveCase() {
string s;
cin >> s;
int end;
for (end = s.size()-1; end >= 0; end--) {
if (!(s[end]-'0'))
break;
}
end++;
int max_consec = s.size()-end;
for (int i = 0, curr = max_consec; i < end; i++) {
if (s[i]-'0')
curr++;
else
curr = 0;
max_consec = max(max_consec, curr);
}
ll ans;
if (max_consec == s.size()) {
ans = (ll)max_consec*max_consec;
} else {
// Ex 5 in row: 5*1, 4*2, 3*3, 2*2, 1*1: 3*3 greatest
// Ex 6 in row 6*1, 5*2, 4*3, 3*4, 2*5, 1*6, 4*3 greatest
ll a = (max_consec & 1) ? (max_consec+1)>>1 : ((max_consec+1)>>1)+1;
ll b = (max_consec+1)>>1;
ans = a*b;
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nC = 1;
cin >> nC;
while (nC--) {
solveCase();
}
return 0;
}