QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99351#6299. Binary StringHunsterWA 307ms5772kbC++141.7kb2023-04-21 22:15:462023-04-21 22:15:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 22:15:47]
  • 评测
  • 测评结果:WA
  • 用时:307ms
  • 内存:5772kb
  • [2023-04-21 22:15:46]
  • 提交

answer

#include <bits/stdc++.h>

char str[10000005];
int n, next[10000005];

int main() {
    int data_count;
    scanf("%d", &data_count);
    for (int data = 1; data <= data_count; data++) {
        scanf("%s", str);
        n = std::strlen(str);
        [&] {
            int cnt0 = 0;
            for (int i = 0; i < n; i++) cnt0 += str[i] == '0';
            if (cnt0 <= n / 2) {
                std::reverse(str, str + n);
                for (int i = 0; i < n; i++) str[i] = str[i] == '0' ? '1' : '0';
            }
        }();
        int ans = [&] {
            int max = 0, cnt = 0;
            for (int i = 0, now = 0; i < 5 * n; i++) {
                int p = i % n;
                if (str[p] == '1') now++, cnt++;
                else now--;
                if (now < 0) now = cnt = 0;
                max = std::max(max, cnt);
            }
            return std::max(max - 1, 0);
        }();
        for (int i = 0, now = 0, tag = 0; i < 5 * n; i++) {
            int p = i % n;
            if (str[p] == '1') now++;
            if (now && !tag) {
                str[p] = '1';
                now--;
                tag = 1;
            }
            else {
                str[p] = '0';
                tag = 0;
            }
        }
        for (int i = n - 1; i >= 0; i--) str[i + 1] = str[i];
        next[1] = 0;
        for (int i = 2, j = 0; i <= n; i++) {
            while (j != 0 && str[j + 1] != str[i]) j = next[j];
            if (str[j + 1] == str[i]) j++;
            next[i] = j;
        }
        if (n % (n - next[n]) == 0) ans += n - next[n];
        else ans += n;
        printf("%d\n", ans);
    }
    return 0;
}
/*
3
1
001001
0001111

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5616kb

input:

3
1
001001
0001111

output:

1
3
9

result:

ok 3 number(s): "1 3 9"

Test #2:

score: -100
Wrong Answer
time: 307ms
memory: 5772kb

input:

262144
000000000000000000
100000000000000000
010000000000000000
110000000000000000
001000000000000000
101000000000000000
011000000000000000
111000000000000000
000100000000000000
100100000000000000
010100000000000000
110100000000000000
001100000000000000
101100000000000000
011100000000000000
11110000...

output:

1
18
18
19
18
19
19
20
18
18
19
20
19
20
20
21
18
18
18
20
19
20
20
21
19
19
20
21
20
21
21
22
18
18
18
19
18
19
20
21
19
19
20
21
20
21
21
22
19
19
19
21
20
21
21
22
20
20
21
22
21
22
22
23
18
18
18
19
18
19
19
21
18
18
19
21
20
21
21
22
19
19
19
21
20
21
21
22
20
20
21
22
21
22
22
23
19
19
19
19
1...

result:

wrong answer 6th numbers differ - expected: '18', found: '19'