QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446472#8521. Pattern Search IIucup-team3678WA 9ms20424kbC++141.2kb2024-06-17 11:08:012024-06-17 11:08:03

Judging History

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

  • [2024-06-17 11:08:03]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:20424kb
  • [2024-06-17 11:08:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int L = 30, N = 1.5e5 + 5;

int c[L], f[L][N];
vector<int> p;

int calc() {
    int x = 0, s = 0;
    for (int i = (int)p.size() - 1; ~i; --i) {
        int t = p[i];
        if (f[t][x] < 0) return s + c[t] + f[t][x] + 1;
        t = f[t][x], s += c[t];
    }
    return 1e9;
}

int dfs(int x) {
    int v;
    if (x < 2) {
        p.push_back(x), v = calc();
    } else {
        v = dfs(x - 2), p.push_back(x - 2), v = min(v, dfs(x - 1));
    }
    p.pop_back(); return v;
}

signed main() {
    string S; cin >> S; int n = S.size();
    for (int i = 0; i < L; ++i) {
        c[i] = (i < 2 ? 1 : c[i - 1] + c[i - 2]);
        f[i][n] = -c[i] - 1;
    }
    for (int i = n - 1; ~i; --i) if (S[i] == 'b') {
        for (int j = 0; j <= i; ++j) f[0][j] = (j + 1 == n ? -1 : j + 1); break;
    }
    for (int i = n - 1; ~i; --i) if (S[i] == 'a') {
        for (int j = 0; j <= i; ++j) f[1][j] = (j + 1 == n ? -1 : j + 1); break;
    }
    for (int i = 2; i < L; ++i) for (int j = 0; j < n; ++j) {
        f[i][j] = f[i - 1][j] < 0 ? f[i - 1][j] - c[i - 2] : f[i - 2][f[i - 1][j]];
    }
    printf("%d\n", dfs(L - 1));
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 20424kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 3ms
memory: 18088kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 8ms
memory: 18156kb

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Wrong Answer
time: 8ms
memory: 20188kb

input:

aa

output:

5

result:

wrong answer 1st numbers differ - expected: '2', found: '5'