QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446467 | #8521. Pattern Search II | ucup-team3678 | WA | 14ms | 6160kb | C++14 | 1.2kb | 2024-06-17 11:04:38 | 2024-06-17 11:04:39 |
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: 7ms
memory: 5868kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: -100
Wrong Answer
time: 14ms
memory: 6160kb
input:
a
output:
1000000000
result:
wrong answer 1st numbers differ - expected: '1', found: '1000000000'