QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#361105 | #6299. Binary String | _l_l_ | WA | 98ms | 8024kb | C++14 | 1.1kb | 2024-03-22 19:48:51 | 2024-03-22 19:48:53 |
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];
dp[1] = 0; for (int i = 2; i <= n << 1; i++) dp[i] = max(str[i - 1] == '1' ? dp[i - 1] + 1 : dp[i - 1] - 1, 0);
int x = 0; for (int i = 1; i <= n << 1; i++) if (str[i] == '1') x = max(x, dp[i]);
int idx = n + 1; while (dp[idx]) idx++;
for (int i = 1, queue = 0; i <= n; i++) {
queue += str[(idx + i - 2) % n + 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 / (n - nxt[n]) : n;
printf("%d\n", x + y);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7980kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 98ms
memory: 8024kb
input:
262144 000000000000000000 100000000000000000 010000000000000000 110000000000000000 001000000000000000 101000000000000000 011000000000000000 111000000000000000 000100000000000000 100100000000000000 010100000000000000 110100000000000000 001100000000000000 101100000000000000 011100000000000000 11110000...
output:
9 9 9 10 9 9 10 11 9 9 9 10 10 10 11 12 9 9 9 10 9 9 10 11 10 10 10 11 11 11 12 13 9 9 9 10 9 9 10 11 9 9 9 10 10 10 11 12 10 10 10 10 10 10 11 12 11 11 11 12 12 12 13 14 9 9 9 10 9 9 10 11 9 9 9 10 10 10 11 12 9 9 9 10 9 9 10 11 10 10 10 11 11 11 12 13 10 10 10 10 10 10 10 11 10 10 10 11 11 11 12 1...
result:
wrong answer 1st numbers differ - expected: '1', found: '9'