QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#496258 | #8521. Pattern Search II | ucup-team1766 | WA | 1ms | 4360kb | C++17 | 1.9kb | 2024-07-28 05:20:59 | 2024-07-28 05:20:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int FIB = 20;
int fibs[FIB];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
fibs[0] = 1;
fibs[1] = 1;
for (int i = 2; i < FIB; i++) {
fibs[i] = fibs[i - 1] + fibs[i - 2];
}
vector<vector<int>> starts(fibs[FIB - 1]);
starts[0].push_back(1);
starts[0].push_back(2);
starts[1].push_back(0);
for (int i = 3; i < FIB; i++) {
starts[0].push_back(i);
for (int j = 0; j < fibs[i - 2]; j++) {
for (int k : starts[j]) {
starts[fibs[i - 1] + j].push_back(k);
}
}
starts[fibs[i - 1]].push_back(i - 2);
}
for (int i = 0; i < FIB - 1; i++) {
sort(starts[i].begin(), starts[i].end());
}
string s;
cin >> s;
int n = s.length();
// dp[i][j] = max subsequence match of s[i...] to S_j
vector<vector<int>> dp(n + 1, vector<int>(FIB));
for (int i = 0; i < n; i++) {
if (s[i] == 'a') {
dp[i][1] = 1;
} else {
dp[i][0] = 1;
}
}
for (int j = 2; j < FIB; j++) {
for (int i = 0; i < n; i++) {
dp[i][j] = max(dp[i][j], dp[i][j - 1] + dp[i + dp[i][j - 1]][j - 2]);
}
}
int res = INT_MAX;
for (int i = 0; i < fibs[FIB - 2]; i++) {
int cur = i;
int ind = 0;
while (true) {
bool moved = false;
for (int j = starts[cur].size() - 1; j >= 0; j--) {
if (ind + dp[ind][starts[cur][j]] < n) {
ind += dp[ind][starts[cur][j]];
cur += fibs[starts[cur][j]];
moved = true;
break;
}
}
if (!moved) {
break;
}
}
res = min(res, cur - i + 1);
}
cout << res << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3752kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 4004kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
bb
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 1ms
memory: 4048kb
input:
ab
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
ba
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
bbba
output:
7
result:
ok 1 number(s): "7"
Test #9:
score: 0
Accepted
time: 0ms
memory: 4068kb
input:
abbbbbbbab
output:
20
result:
ok 1 number(s): "20"
Test #10:
score: 0
Accepted
time: 1ms
memory: 4052kb
input:
abbbbabbbabbbabbabaabbabb
output:
43
result:
ok 1 number(s): "43"
Test #11:
score: 0
Accepted
time: 1ms
memory: 4016kb
input:
bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba
output:
94
result:
ok 1 number(s): "94"
Test #12:
score: 0
Accepted
time: 1ms
memory: 4088kb
input:
ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb
output:
245
result:
ok 1 number(s): "245"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3928kb
input:
aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...
output:
625
result:
ok 1 number(s): "625"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...
output:
1608
result:
ok 1 number(s): "1608"
Test #15:
score: -100
Wrong Answer
time: 0ms
memory: 4360kb
input:
aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...
output:
2586
result:
wrong answer 1st numbers differ - expected: '3954', found: '2586'