QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446478#8521. Pattern Search IIucup-team3678WA 4ms20416kbC++141.2kb2024-06-17 11:18:162024-06-17 11:18:17

Judging History

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

  • [2024-06-17 11:18:17]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:20416kb
  • [2024-06-17 11:18:16]
  • 提交

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;
        x = 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: 0
Wrong Answer
time: 4ms
memory: 20416kb

input:

aabbaab

output:

7

result:

wrong answer 1st numbers differ - expected: '8', found: '7'