QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#301255#6299. Binary StringyllcmWA 77ms8000kbC++141.4kb2024-01-09 16:42:002024-01-09 16:42:00

Judging History

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

  • [2024-01-09 16:42:00]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:8000kb
  • [2024-01-09 16:42:00]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
  int x = 0; bool op = false;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 1e7 + 10;
int n;
int a[N], b[N], nxt[N];
char buff[N];
void solve() {
  scanf("%s", buff + 1); n = strlen(buff + 1);
  for(int i = 1; i <= n; i++)a[i] = buff[i] - '0';
  int cnt = 0;
  for(int i = 1; i <= n; i++)cnt += a[i];
  if(cnt > n / 2) {
    for(int i = 1; i <= n; i++)a[i] ^= 1;
    reverse(a + 1, a + 1 + n);
  }
  cnt = 0; int pos = 0, ans = 0;
  for(int i = 1; i <= n; i++)ans += (a[i] && a[i % n + 1]);
  for(int i = 1; i <= n; i++)if(!a[i]) {pos = i; break;}
  rotate(a + 1, a + pos, a + 1 + n);
  for(int i = 1; i <= n; i++) {
    cnt += a[i];
    if(cnt && !b[i - 1])b[i] = 1, cnt--;
  }
  for(int i = 2, j = 0; i <= n; i++) {
    while(j && a[j + 1] != a[i])j = nxt[j];
    if(a[j + 1] == a[i])j++;
    nxt[i] = j;
  }
  int cur = nxt[n];
  while(n % (n - cur))cur = nxt[cur];
  ans += n - cur;
  printf("%d\n", ans);
  return ;
}
int main() {
  int test = read();
  while(test--)solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5952kb

input:

3
1
001001
0001111

output:

1
3
9

result:

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

Test #2:

score: -100
Wrong Answer
time: 77ms
memory: 8000kb

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
20
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
20
1...

result:

wrong answer 12th numbers differ - expected: '20', found: '19'