QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446472 | #8521. Pattern Search II | ucup-team3678 | WA | 9ms | 20424kb | C++14 | 1.2kb | 2024-06-17 11:08:01 | 2024-06-17 11:08:03 |
Judging History
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;
}
詳細信息
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'