QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446212#8521. Pattern Search IIucup-team3215RE 0ms3788kbC++201.1kb2024-06-17 01:38:572024-06-17 01:38:59

Judging History

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

  • [2024-06-17 01:38:59]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3788kb
  • [2024-06-17 01:38:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  string s; cin >> s;
  int n = s.size();
  string pat = "ba";
  vector<int> fib{1, 1};
  vector<vector<int>> jmp;
  for (int j: {0, 1}) {
    jmp.push_back(vector(n, 0));
    for (int i = 0; i < n; ++i) jmp[j][i] = i + (s[i] == 'b' - j);
  }
  for (int more = 1; jmp.back()[0] < n || more--; ) {
    fib.push_back(fib.end()[-2] + fib.end()[-1]);
    int j = jmp.size() - 1;
    jmp.push_back(vector(n, 0));
    for (int i = 0; i < n; ++i) jmp[j + 1][i] = jmp[j][i] == n? n: jmp[j - 1][jmp[j][i]];
  }
  int ans = 1e9;
  vector<int> v{fib.size() - 1};
  do {
    if (v.back() > 1) {
      v.push_back(v.back() - 1);
      v.end()[-2] -= 2;
      continue;
    } else if (pat[v.back()] != s[0]) {
      v.pop_back();
      continue;
    }
    int l = 0, i = v.size() - 1, j = 0;
    while (jmp[v[i]][j] < n) l += fib[v[i]], j = jmp[v[i--]][j];
    int c = v[i];
    while (c > 1) jmp[c - 1][j] < n? j = jmp[c - 1][j], l += fib[c - 1], c -= 2: --c;
    ans = min(ans, l + 1);
    v.pop_back();
  } while (v.size() > 1);
  cout << ans;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3788kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: -100
Runtime Error

input:

bbba

output:


result: