QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411356#6299. Binary StringSamponYWRE 1ms3864kbC++142.3kb2024-05-15 12:00:002024-05-15 12:00:00

Judging History

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

  • [2024-05-15 12:00:00]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3864kb
  • [2024-05-15 12:00:00]
  • 提交

answer

#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 10000005
#define P 998244353
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
  int s = 1;
  while(n) {
    if(n & 1) s = 1ll * s * p % P;
    p = 1ll * p * p % P, n >>= 1;
  }
  return s;
}
string str; int n, v[N];
int f[N];
int u[N];
il void WORK() {
  cin >> str, n = SZ(str);
  int cnt = 0; for(auto c : str) cnt += c & 1;
  if(!cnt || cnt == n) {cout << "1\n"; return ;}
  if(cnt > n - cnt) {for(auto &c : str) c ^= 1; reverse(ALL(str));}
  int num = 0;
  FOR(i, 0, n - 1) if(str[i] == '0') {
    rotate(str.begin(), str.begin() + i, str.end()); break;
  }
  str = " " + str;
  int m = 0;
  FOR(i, 1, n) if(str[i] == '0') {
    int j = i + 1; while(j <= n && str[j] == '1') ++j;
    v[++m] = j - i - 1, i = j - 1;
  }
  int mn = 0, id = 1, sum = 0;
  FOR(i, 1, m) {
    sum += v[i] - 1;
    if(sum < mn) mn = sum, id = i;
  }
  rotate(v + 1, v + id, v + 1 + m);
  int ans = 0;
  FOR(i, 1, m) if(v[i] > 1) {
    int now = 0, j = i;
    for(; ; ) {
      now += v[j] - 1; if(now <= 0) break; ++j;
    }
    ans = max(ans, j - i);
    FOR(k, i, j) v[k] = 1;
  }
  int L = 0;
  FOR(i, 1, m) {
    str[++L] = '0';
    if(v[i]) str[++L] = '1';
  }
  assert(L == n);
  int j = 0;
  FOR(i, 2, n) {
    while(j && str[j + 1] != str[i]) j = f[j];
    if(str[j + 1] == str[i]) ++j; f[i] = j;
  }
  int k = n - f[n];
  if(n % k == 0) ans += k;
  else ans += n;
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int T; cin >> T;
  while(T--) WORK();
  cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
001001
0001111

output:

1
3
9

result:

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

Test #2:

score: -100
Runtime Error

input:

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

output:


result: