File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = long long ;
5
+
6
+ int count (string const & S) {
7
+ int const n = S.size ();
8
+ int ans = 0 ;
9
+ int i = 0 ;
10
+ int l = 0 ;
11
+ int m = 0 ;
12
+ while (i < n) {
13
+ if (S[i] == ' 1' ) {
14
+ if (m == 0 ) l = i;
15
+ ++m;
16
+ } else if (m > 0 ) {
17
+ int r = n - l - m;
18
+ int k = min ({ n - l, n - r, l + m, m + r });
19
+ ans = max (ans, k);
20
+ m = 0 ;
21
+ }
22
+ ++i;
23
+ }
24
+ if (m > 0 ) {
25
+ int r = n - l - m;
26
+ int k = min ({ n - l, n - r, l + m, m + r });
27
+ ans = max (ans, k);
28
+ }
29
+ return ans;
30
+ }
31
+
32
+ int solve (string& S) {
33
+ int ans = count (S);
34
+ for (int i = 0 ; i < S.size (); ++i) {
35
+ S[i] = S[i] == ' 0' ? ' 1' : ' 0' ;
36
+ }
37
+ ans = max (ans, count (S));
38
+ return ans;
39
+ }
40
+
41
+ int main () {
42
+ ios_base::sync_with_stdio (false );
43
+ cin.tie (0 ); cout.tie (0 );
44
+
45
+ string S;
46
+ cin >> S;
47
+ cout << solve (S) << endl;
48
+
49
+ return 0 ;
50
+ }
You can’t perform that action at this time.
0 commit comments