QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361153 | #6299. Binary String | _l_l_ | WA | 87ms | 5984kb | C++14 | 1.3kb | 2024-03-22 20:49:24 | 2024-03-22 20:49:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000005;
char str[MAXN << 1], str2[MAXN]; int dp[MAXN << 1], nxt[MAXN];
int main() {
int t; scanf("%d", &t); while (t--) {
scanf("%s", str + 1); int n = strlen(str + 1);
int m = 0; for (int i = 1; i <= n; i++) m += str[i] == '1';
if (m > n / 2) {
reverse(str + 1, str + 1 + n), m = n - m; for (int i = 1; i <= n; i++) str[i] ^= 1;
}
for (int i = 1; i <= n; i++) str[i + n] = str[i];
pair<int, int> W = {-0x3f3f3f3f, 0}; int cnt = 0, x = 0; for (int i = 1; i <= n << 1; i++) {
if (str[i] == '0') continue; cnt++; pair<int, int> tmp = {i - 2 * cnt, cnt};
W = max(W, tmp); if (tmp.first < W.first) x = max(x, (cnt - W.second) * 2 - (i - (W.first + 2 * W.second)));
}
int idx = W.second == 0 ? 1 : W.second * 2 + W.first;
for (int i = 1, queue = 0; i <= n; i++) {
queue += str[(idx + i - 2) % n + 1] == '1'; str2[i] = str2[i - 1] != '1' && queue ? '1' : '0';
queue -= str2[i] == '1';
}
for (int i = 2; i <= n; i++) {
nxt[i] = nxt[i - 1]; while (nxt[i] && str2[i] != str2[nxt[i] + 1]) nxt[i] = nxt[nxt[i]];
if (str2[i] == str2[nxt[i] + 1]) nxt[i]++;
}
int y = n % (n - nxt[n]) == 0 ? n - nxt[n] : n;
printf("%d\n", x + y);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5984kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 87ms
memory: 5892kb
input:
262144 000000000000000000 100000000000000000 010000000000000000 110000000000000000 001000000000000000 101000000000000000 011000000000000000 111000000000000000 000100000000000000 100100000000000000 010100000000000000 110100000000000000 001100000000000000 101100000000000000 011100000000000000 11110000...
output:
1 18 18 19 18 18 19 20 18 18 18 19 19 19 20 21 18 18 18 19 18 18 19 20 19 19 19 20 20 20 21 22 18 18 18 19 18 18 19 20 18 18 18 19 19 19 20 21 19 19 19 19 19 19 20 21 20 20 20 21 21 21 22 23 18 18 18 19 18 18 19 20 18 18 18 19 19 19 20 21 18 18 18 19 18 18 19 20 19 19 19 20 20 20 21 22 19 19 19 19 1...
result:
wrong answer 12th numbers differ - expected: '20', found: '19'