-
Notifications
You must be signed in to change notification settings - Fork 0
/
B_JoJo_s_Incredible_Adventures.cpp
86 lines (84 loc) · 1.72 KB
/
B_JoJo_s_Incredible_Adventures.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define loop(o, n) for (int i = 0; i < n; i++)
#define py cout << "YES" << endl
#define pn cout << "NO" << endl
using namespace std;
// #define m 1e9+7
int getMaxLength(string s, int n)
{
int start = 0;
int preCnt = 0;
while (start < n && s[start] == '1')
{
preCnt++;
start++;
}
int end = n - 1;
int suffCnt = 0;
while (end >= 0 && s[end] == '1')
{
suffCnt++;
end--;
}
if (start > end)
return n;
int midCnt = 0;
int result = 0;
for (int i = start; i <= end; i++)
{
if (s[i] == '1')
{
midCnt++;
result = max(result, midCnt);
}
else
{
midCnt = 0;
}
}
return max(result, preCnt + suffCnt);
}
int main()
{
int t = 1;
cin >> t;
while (t--)
{
string s1;
cin >> s1;
string s = s1 + s1;
ll n = s.length();
long long int co = 0, cnt = 0;
for (int i = 0; i <= n; i++)
{
if (s[i] == '1')
{
co++;
}
else
{
cnt = max(cnt, co);
co = 0;
}
}
if (cnt >= s1.size())
{
cout << (long long int)s1.size() * s1.size() << endl;
}
else
{
cout << ((cnt + 1) / 2) * (cnt - (cnt + 1) / 2 + 1) << endl;
}
}
return 0;
}