QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#361105#6299. Binary String_l_l_WA 98ms8024kbC++141.1kb2024-03-22 19:48:512024-03-22 19:48:53

Judging History

你现在查看的是最新测评结果

  • [2024-03-22 19:48:53]
  • 评测
  • 测评结果:WA
  • 用时:98ms
  • 内存:8024kb
  • [2024-03-22 19:48:51]
  • 提交

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);
	}
}

Details

Tip: Click on the bar to expand more detailed information

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'