QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446154 | #8521. Pattern Search II | ucup-team1069 | WA | 15ms | 118720kb | C++20 | 2.5kb | 2024-06-16 22:45:23 | 2024-06-16 22:45:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
const int N = 3e5 + 20;
const int mod = 1e9 + 7;
const int inf = 1e9;
string s[30], t;
int dp[30][N], pd[30][N], can[30][N], nac[30][N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
const int K = 23;
s[0] = "b";
s[1] = "a";
cin >> t;
int n = sz(t);
t = "#" + t;
for (int j = 1; j <= n; ++j) {
if (s[0][0] == t[j]) {
can[0][j] = 1;
dp[0][j] = 1;
}
if (s[1][0] == t[j]) {
can[1][j] = 1;
dp[1][j] = 1;
}
}
for (int i = 2; i <= K; ++i) {
s[i] = s[i - 1] + s[i - 2];
for (int j = 1; j <= n; ++j) {
dp[i][j] = inf;
if (can[i - 2][j] == j) {
dp[i][j] = dp[i - 2][j];
can[i][j] = j;
}
else {
if (can[i - 1][j - can[i - 2][j]] + can[i - 2][j] == j) {
dp[i][j] = dp[i - 1][j - can[i - 2][j]] + sz(s[i - 2]);
can[i][j] = j;
}
else {
dp[i][j] = sz(s[i]);
can[i][j] = can[i - 1][j - can[i - 2][j]] + can[i - 2][j];
}
}
}
}
reverse(t.begin() + 1, t.end());
for (int j = 1; j <= n; ++j) {
if (s[0][0] == t[j]) {
nac[0][j] = 1;
pd[0][j] = 1;
}
if (s[1][0] == t[j]) {
nac[1][j] = 1;
pd[1][j] = 1;
}
}
for (int i = 2; i <= K; ++i) {
for (int j = 1; j <= n; ++j) {
pd[i][j] = inf;
if (nac[i - 1][j] == j) {
pd[i][j] = pd[i - 1][j];
nac[i][j] = j;
}
else {
if (nac[i - 2][j - nac[i - 1][j]] + nac[i - 1][j] == j) {
pd[i][j] = pd[i - 2][j - nac[i - 1][j]] + sz(s[i - 1]);
nac[i][j] = j;
}
else {
pd[i][j] = sz(s[i]);
nac[i][j] = nac[i - 2][j - nac[i - 1][j]] + nac[i - 1][j];
}
}
}
}
int ans = inf;
for (int i = 1; i <= K; ++i) {
if (can[i][n] == n)
ans = min(ans, dp[i][n]);
for (int j = 1; j < n; ++j) {
if (can[i][j] + nac[i - 1][n - j] == n) {
ans = min(ans, dp[i][j] + pd[i - 1][n - j]);
}
}
}
cout << ans << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 118676kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 112528kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 116552kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 112284kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 116584kb
input:
bb
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 118376kb
input:
ab
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 118432kb
input:
ba
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 0ms
memory: 118368kb
input:
bbba
output:
7
result:
ok 1 number(s): "7"
Test #9:
score: 0
Accepted
time: 0ms
memory: 118372kb
input:
abbbbbbbab
output:
20
result:
ok 1 number(s): "20"
Test #10:
score: 0
Accepted
time: 3ms
memory: 116636kb
input:
abbbbabbbabbbabbabaabbabb
output:
43
result:
ok 1 number(s): "43"
Test #11:
score: 0
Accepted
time: 3ms
memory: 116424kb
input:
bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba
output:
94
result:
ok 1 number(s): "94"
Test #12:
score: 0
Accepted
time: 0ms
memory: 118600kb
input:
ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb
output:
245
result:
ok 1 number(s): "245"
Test #13:
score: 0
Accepted
time: 0ms
memory: 118464kb
input:
aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...
output:
625
result:
ok 1 number(s): "625"
Test #14:
score: 0
Accepted
time: 0ms
memory: 118444kb
input:
aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...
output:
1608
result:
ok 1 number(s): "1608"
Test #15:
score: 0
Accepted
time: 3ms
memory: 118380kb
input:
aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...
output:
3954
result:
ok 1 number(s): "3954"
Test #16:
score: 0
Accepted
time: 0ms
memory: 118704kb
input:
aaabbbbabaaabbabbaabbabbbbbbbaaabbaaaaabbbbbaaaabbbaaabbabbaabaabbbaabaababaabbbababbbbbbabbababbbbabaaababbbaaabbabbbaabbbbbbbbbbabbbbbabbabbbbabbbbbbbaabaaaaaabbbaaabaabaaaaabbabbaaabbababaaaaaababbbabaabbbaabaaabaabbabaaaaababaaabbaabaababbaaabaabbaabbbbaababbaabaaabababbbbbabbbbababbbbbbaabbabab...
output:
10033
result:
ok 1 number(s): "10033"
Test #17:
score: 0
Accepted
time: 0ms
memory: 116684kb
input:
aabbbbbabababbbababaaabaabbbbbbaaababaabaababbbbbaabaabababaabbbbbbaabbbababbbbbbbbbbabababbabbaaaabaaaaabbabbbabbaaaaababababaaabbbbbbbabbbbbbbbaaabbbaaababbaaaaaabaabbaababbbabaaabbbaabbabababbaaaababbbabbbabaaaaabbbabbbabbaaaabababbbbbbaabbbaaaabbabbabbabbbbbbbaabbbaabbbbabbbaabbbbbbabaaaabbaaabb...
output:
24882
result:
ok 1 number(s): "24882"
Test #18:
score: 0
Accepted
time: 3ms
memory: 118600kb
input:
bbabaaababbabbbbbbababaababaaabababaabbbaabbbabbababbbbbabbbbaaabbbbaaaaabbaaabbbabbbbaabaabbaaaabaababbbababbbbaaaaabaabaababbbbbabbbabbaaabbabbbbaabbabababababababaabbaabbaabbabaaaabaaabbbbbababbbbaaaaabaababbbbabaaaabababaaabaaaabbbbabbbbabaaaaaababbbbabaaabaaaabaaabaabaabaabaaabbabbbbabbababaaab...
output:
62283
result:
ok 1 number(s): "62283"
Test #19:
score: -100
Wrong Answer
time: 15ms
memory: 118720kb
input:
bbbaabaababbaababbbbbbabbbbbbabaabbaaaaabbabbbbbabbabaabbbbaabaaababaaababbaaabababbabbababbbabaabbbabbabbabaabbbbaabaaabbaaabaaabbaaaaabaababbaabaaaabbbbababaababbabaaabababbaabbabbbabbababaaabbbbbabababbaabbbabaaabbaabaababaabbbaabbbaaabbbbabaabbbaaaabbbababaabbaaabaaababbbaabbbaabbbbbabababbababb...
output:
1000000000
result:
wrong answer 1st numbers differ - expected: '155673', found: '1000000000'