QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446484#8521. Pattern Search IIucup-team3678WA 11ms20188kbC++141.2kb2024-06-17 11:30:152024-06-17 11:30:15

Judging History

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

  • [2024-06-17 11:30:15]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:20188kb
  • [2024-06-17 11:30:15]
  • 提交

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) {
        	if (s + c[t] + f[t][x] + 1 == 7) {
        		puts("!");
			}
			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;
    }
    iota(f[0], f[0] + n, 0), iota(f[1], f[1] + n, 0);
    for (int i = n - 1; ~i; --i) {
        f[S[i] == 'a'][i] = (i + 1 == n ? -1 : i + 1);
    }
    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;
}

详细

Test #1:

score: 100
Accepted
time: 11ms
memory: 20188kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 6ms
memory: 20184kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 6ms
memory: 18148kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 9ms
memory: 20128kb

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 9ms
memory: 20132kb

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: -100
Wrong Answer
time: 9ms
memory: 20128kb

input:

bbba

output:

!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
...

result:

wrong output format Expected integer, but "!" found