Submission #4556340
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2019/03/12 Problem: ABC 083 D / Link: http://abc083.contest.atcoder.jp/tasks/abc083_d ----- */
struct Cumusum {
vector<LL>csum;
Cumusum(vector<LL>&a) {
csum.assign((int)a.size() + 1, 0);
for (int i = 0; i < (int)a.size(); i++) {
csum[i + 1] = csum[i] + a[i];
}
}
LL query(int l, int r) {
return csum[r] - csum[l];
}
};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
string s; cin >> s;
VL z(SZ(s));
FOR(i, 0, SZ(s)) {
z[i] = s[i] == '0';
}
Cumusum zeros(z);
LL ans = (SZ(s) + 1) / 2;
int L = SZ(s) / 2 - 1;
int R = (SZ(s) & 1 ? SZ(s) / 2 + 1 : SZ(s) / 2);
while (10) {
if (L < 0 || R >= SZ(s))break;
int W = R - L + 1;
LL sum = zeros.query(L, R + 1);
if (W == sum || !sum) {
// ok
ans = max(ans, (LL)SZ(s) - L);
}
else break;
L--, R++;
}
cout << (ans) << "\n";
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Wide Flip |
| User |
Yang33 |
| Language |
C++14 (GCC 5.4.1) |
| Score |
500 |
| Code Size |
1867 Byte |
| Status |
AC |
| Exec Time |
3 ms |
| Memory |
2000 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
s1.txt, s2.txt, s3.txt |
| All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, s1.txt, s2.txt, s3.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01.txt |
AC |
3 ms |
2000 KiB |
| 02.txt |
AC |
3 ms |
2000 KiB |
| 03.txt |
AC |
3 ms |
2000 KiB |
| 04.txt |
AC |
3 ms |
2000 KiB |
| 05.txt |
AC |
3 ms |
2000 KiB |
| 06.txt |
AC |
3 ms |
2000 KiB |
| 07.txt |
AC |
3 ms |
2000 KiB |
| 08.txt |
AC |
3 ms |
2000 KiB |
| 09.txt |
AC |
3 ms |
2000 KiB |
| 10.txt |
AC |
3 ms |
2000 KiB |
| 11.txt |
AC |
3 ms |
2000 KiB |
| 12.txt |
AC |
3 ms |
2000 KiB |
| 13.txt |
AC |
3 ms |
2000 KiB |
| 14.txt |
AC |
3 ms |
2000 KiB |
| 15.txt |
AC |
3 ms |
2000 KiB |
| 16.txt |
AC |
3 ms |
2000 KiB |
| 17.txt |
AC |
3 ms |
2000 KiB |
| 18.txt |
AC |
3 ms |
2000 KiB |
| 19.txt |
AC |
3 ms |
2000 KiB |
| 20.txt |
AC |
3 ms |
2000 KiB |
| 21.txt |
AC |
1 ms |
256 KiB |
| 22.txt |
AC |
1 ms |
256 KiB |
| 23.txt |
AC |
1 ms |
256 KiB |
| 24.txt |
AC |
1 ms |
256 KiB |
| 25.txt |
AC |
1 ms |
256 KiB |
| 26.txt |
AC |
1 ms |
256 KiB |
| 27.txt |
AC |
1 ms |
256 KiB |
| s1.txt |
AC |
1 ms |
256 KiB |
| s2.txt |
AC |
1 ms |
256 KiB |
| s3.txt |
AC |
1 ms |
256 KiB |