QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#443837#8521. Pattern Search IIucup-team896#WA 3898ms20164kbC++202.7kb2024-06-15 16:38:432024-06-15 16:38:45

Judging History

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

  • [2024-06-15 16:38:45]
  • 评测
  • 测评结果:WA
  • 用时:3898ms
  • 内存:20164kb
  • [2024-06-15 16:38:43]
  • 提交

answer

#pragma GCC optimize("Ofast","unroll-loops")

#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 450010;
mt19937 rnd(random_device{}());

string s, t;
int n, m, a[maxn], b[maxn], to[maxn][2], ot[maxn][2];
vector<pii> val;

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  s = "a"s, t = "b"s;
  while (SZ(t) < 450000) {
    string p = s + t;
    t = s, s = p;
  }
  t.resize(450000);
  cin >> s;
  n = SZ(s), m = SZ(t);
  rep (i, 1, n) a[i] = s[i - 1] - 'a';
  rep (i, 1, m) b[i] = t[i - 1] - 'a';
  vector<int> vec;
  rep (i, 1, m - 1) {
    vec.emplace_back(b[i]);
    if (b[i] == b[i + 1] && b[i] == 1) vec.emplace_back(0);
  }
  vec.emplace_back(b[m]);
  m = SZ(vec);
  rep (i, 1, m) b[i] = vec[i - 1];
  to[m + 1][0] = to[m + 1][1] = m + 1;
  per (i, m, 1) {
    to[i][0] = to[i + 1][0], to[i][1] = to[i + 1][1];
    if (i != m) to[i][b[i + 1]] = i + 1;
  }
  ot[0][0] = ot[0][1] = 0;
  rep (i, 1, m) {
    ot[i][0] = ot[i - 1][0], ot[i][1] = ot[i - 1][1];
    if (i != 1) ot[i][b[i - 1]] = i - 1;
  }
  if (n <= 300) {
    rep (i, 1, m - n + 1) if (a[1] == b[i]) {
      int pos = i;
      rep (j, 2, min(n, 300)) {
        pos = to[pos][a[j]];
        if (pos > m) break;
      }
      if (pos > m) continue;
      val.emplace_back(pos - i, i);
    }
    sort(ALL(val));
    int ans = 1e9;
    for (auto [len, i] : val) {
      if (clock() / CLOCKS_PER_SEC > 3.5) break;
      int pos = i;
      rep (j, 2, n) {
        pos = to[pos][a[j]];
        if (pos > m) break;
      }
      if (pos > m) continue;
      chkmn(ans, pos - i + 1);
    }
    cout << ans << '\n';
    return 0;
  }
  // int S = uniform_int_distribution<int>(1, n - 299)(rnd), T = S + 299;
  int S = 1, T = 300;
  rep (i, 1, m - 299) {
    if (b[i] != a[S]) continue;
    int pos = i;
    rep (j, S + 1, T) pos = to[pos][a[j]];
    if (pos <= m) val.emplace_back(pos - i, i);
  }
  sort(ALL(val));
  int ans = 1e9;
  for (auto [fool, i] : val) {
    if (1. * clock() / CLOCKS_PER_SEC >= 3.9) break;
    int R = i, L = i;
    rep (j, S + 1, n) R = to[R][a[j]];
    per (j, S - 1, 1) L = ot[L][a[j]];
    if (R <= m && L >= 1) chkmn(ans, R - L + 1);
  }
  cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 28ms
memory: 19240kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 31ms
memory: 19248kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 12ms
memory: 18192kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 16ms
memory: 19228kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 20ms
memory: 18220kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 24ms
memory: 19188kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 7ms
memory: 18244kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 11ms
memory: 18332kb

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: 0
Accepted
time: 24ms
memory: 19404kb

input:

abbbbbbbab

output:

20

result:

ok 1 number(s): "20"

Test #10:

score: 0
Accepted
time: 69ms
memory: 19188kb

input:

abbbbabbbabbbabbabaabbabb

output:

43

result:

ok 1 number(s): "43"

Test #11:

score: 0
Accepted
time: 54ms
memory: 18152kb

input:

bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba

output:

94

result:

ok 1 number(s): "94"

Test #12:

score: 0
Accepted
time: 179ms
memory: 19236kb

input:

ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb

output:

245

result:

ok 1 number(s): "245"

Test #13:

score: 0
Accepted
time: 359ms
memory: 19360kb

input:

aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...

output:

625

result:

ok 1 number(s): "625"

Test #14:

score: 0
Accepted
time: 632ms
memory: 19256kb

input:

aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...

output:

1608

result:

ok 1 number(s): "1608"

Test #15:

score: 0
Accepted
time: 1326ms
memory: 19188kb

input:

aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...

output:

3954

result:

ok 1 number(s): "3954"

Test #16:

score: 0
Accepted
time: 3545ms
memory: 19428kb

input:

aaabbbbabaaabbabbaabbabbbbbbbaaabbaaaaabbbbbaaaabbbaaabbabbaabaabbbaabaababaabbbababbbbbbabbababbbbabaaababbbaaabbabbbaabbbbbbbbbbabbbbbabbabbbbabbbbbbbaabaaaaaabbbaaabaabaaaaabbabbaaabbababaaaaaababbbabaabbbaabaaabaabbabaaaaababaaabbaabaababbaaabaabbaabbbbaababbaabaaabababbbbbabbbbababbbbbbaabbabab...

output:

10033

result:

ok 1 number(s): "10033"

Test #17:

score: 0
Accepted
time: 3881ms
memory: 19304kb

input:

aabbbbbabababbbababaaabaabbbbbbaaababaabaababbbbbaabaabababaabbbbbbaabbbababbbbbbbbbbabababbabbaaaabaaaaabbabbbabbaaaaababababaaabbbbbbbabbbbbbbbaaabbbaaababbaaaaaabaabbaababbbabaaabbbaabbabababbaaaababbbabbbabaaaaabbbabbbabbaaaabababbbbbbaabbbaaaabbabbabbabbbbbbbaabbbaabbbbabbbaabbbbbbabaaaabbaaabb...

output:

24882

result:

ok 1 number(s): "24882"

Test #18:

score: 0
Accepted
time: 3882ms
memory: 18244kb

input:

bbabaaababbabbbbbbababaababaaabababaabbbaabbbabbababbbbbabbbbaaabbbbaaaaabbaaabbbabbbbaabaabbaaaabaababbbababbbbaaaaabaabaababbbbbabbbabbaaabbabbbbaabbabababababababaabbaabbaabbabaaaabaaabbbbbababbbbaaaaabaababbbbabaaaabababaaabaaaabbbbabbbbabaaaaaababbbbabaaabaaaabaaabaabaabaabaaabbabbbbabbababaaab...

output:

62283

result:

ok 1 number(s): "62283"

Test #19:

score: 0
Accepted
time: 3890ms
memory: 18556kb

input:

bbbaabaababbaababbbbbbabbbbbbabaabbaaaaabbabbbbbabbabaabbbbaabaaababaaababbaaabababbabbababbbabaabbbabbabbabaabbbbaabaaabbaaabaaabbaaaaabaababbaabaaaabbbbababaababbabaaabababbaabbabbbabbababaaabbbbbabababbaabbbabaaabbaabaababaabbbaabbbaaabbbbabaabbbaaaabbbababaabbaaabaaababbbaabbbaabbbbbabababbababb...

output:

155673

result:

ok 1 number(s): "155673"

Test #20:

score: 0
Accepted
time: 3878ms
memory: 19524kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

121390

result:

ok 1 number(s): "121390"

Test #21:

score: 0
Accepted
time: 3885ms
memory: 18760kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

196413

result:

ok 1 number(s): "196413"

Test #22:

score: 0
Accepted
time: 3890ms
memory: 20164kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

121392

result:

ok 1 number(s): "121392"

Test #23:

score: 0
Accepted
time: 3878ms
memory: 18492kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

196416

result:

ok 1 number(s): "196416"

Test #24:

score: 0
Accepted
time: 3891ms
memory: 19512kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

121394

result:

ok 1 number(s): "121394"

Test #25:

score: 0
Accepted
time: 3889ms
memory: 18420kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

196419

result:

ok 1 number(s): "196419"

Test #26:

score: 0
Accepted
time: 3882ms
memory: 19832kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

196415

result:

ok 1 number(s): "196415"

Test #27:

score: 0
Accepted
time: 3886ms
memory: 18632kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

317806

result:

ok 1 number(s): "317806"

Test #28:

score: 0
Accepted
time: 3890ms
memory: 20156kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

196417

result:

ok 1 number(s): "196417"

Test #29:

score: 0
Accepted
time: 3898ms
memory: 18620kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

317809

result:

ok 1 number(s): "317809"

Test #30:

score: -100
Wrong Answer
time: 3886ms
memory: 19968kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

196419

result:

wrong answer 1st numbers differ - expected: '196418', found: '196419'