QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#445502 | #8521. Pattern Search II | ucup-team3695# | TL | 677ms | 8112kb | C++20 | 1.6kb | 2024-06-16 03:09:12 | 2024-06-16 03:09:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int constexpr LIM = 450000;
int main()
{
int a = 1, b = 2;
string s;
cin >> s;
string A = "b", B = "a";
while (size(B) < LIM)
{
A = B + A;
A.swap(B);
}
vector<pair<int, char>> J(LIM, {-1, '\0'});
char c = 'a', d = 'b';
while (b - 2 < LIM)
{
tie(a, b) = pair{b, a + b};
swap(c, d);
J[a - 2] = {b - 1, c};
}
vector<pair<int, int>> DP, EP;
DP.emplace_back(0, 0);
int ans = -1;
bool done = false;
while (!done)
{
ans++;
EP.clear();
for (auto [i, j] : DP)
{
if (j == (int)size(s))
{
done = true;
break;
}
char ch = s[j];
EP.emplace_back(i + 1, j + (ch == B[i]));
if (J[i].second)
EP.emplace_back(J[i].first, j + (ch == J[i].second));
}
EP.swap(DP);
}
cout << ans;
// long long ans = (int)size(s);
// deque<char> S(begin(s), end(s)), T;
// for (;;)
// {
// tie(a, b) = pair{b, a + b};
// if (S.size() == 1)
// break;
// if (S.front() == 'b')
// S.push_front('a');
// if (S.back() == 'a')
// S.pop_back();
// if (S.size() == 1)
// break;
// T.clear();
// for (int i = 0; i < (int)size(S);)
// {
// if (S[i] == 'a')
// {
// if (i < (int)size(S) - 1 && S[i + 1] == 'b')
// {
// T.push_back('a');
// i += 2;
// }
// else
// {
// T.push_back('b');
// i++;
// }
// }
// else
// {
// T.push_back('a');
// i++;
// ans += b;
// }
// }
// S.swap(T);
// }
// cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7656kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 7556kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 7604kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 7748kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 2ms
memory: 7608kb
input:
bb
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 2ms
memory: 7640kb
input:
ab
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 7624kb
input:
ba
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 0ms
memory: 7604kb
input:
bbba
output:
7
result:
ok 1 number(s): "7"
Test #9:
score: 0
Accepted
time: 2ms
memory: 7612kb
input:
abbbbbbbab
output:
20
result:
ok 1 number(s): "20"
Test #10:
score: 0
Accepted
time: 0ms
memory: 7720kb
input:
abbbbabbbabbbabbabaabbabb
output:
43
result:
ok 1 number(s): "43"
Test #11:
score: 0
Accepted
time: 2ms
memory: 7736kb
input:
bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba
output:
94
result:
ok 1 number(s): "94"
Test #12:
score: 0
Accepted
time: 0ms
memory: 7732kb
input:
ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb
output:
245
result:
ok 1 number(s): "245"
Test #13:
score: 0
Accepted
time: 3ms
memory: 7644kb
input:
aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...
output:
625
result:
ok 1 number(s): "625"
Test #14:
score: 0
Accepted
time: 5ms
memory: 7632kb
input:
aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...
output:
1608
result:
ok 1 number(s): "1608"
Test #15:
score: 0
Accepted
time: 14ms
memory: 7656kb
input:
aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...
output:
3954
result:
ok 1 number(s): "3954"
Test #16:
score: 0
Accepted
time: 106ms
memory: 7888kb
input:
aaabbbbabaaabbabbaabbabbbbbbbaaabbaaaaabbbbbaaaabbbaaabbabbaabaabbbaabaababaabbbababbbbbbabbababbbbabaaababbbaaabbabbbaabbbbbbbbbbabbbbbabbabbbbabbbbbbbaabaaaaaabbbaaabaabaaaaabbabbaaabbababaaaaaababbbabaabbbaabaaabaabbabaaaaababaaabbaabaababbaaabaabbaabbbbaababbaabaaabababbbbbabbbbababbbbbbaabbabab...
output:
10033
result:
ok 1 number(s): "10033"
Test #17:
score: 0
Accepted
time: 677ms
memory: 8112kb
input:
aabbbbbabababbbababaaabaabbbbbbaaababaabaababbbbbaabaabababaabbbbbbaabbbababbbbbbbbbbabababbabbaaaabaaaaabbabbbabbaaaaababababaaabbbbbbbabbbbbbbbaaabbbaaababbaaaaaabaabbaababbbabaaabbbaabbabababbaaaababbbabbbabaaaaabbbabbbabbaaaabababbbbbbaabbbaaaabbabbabbabbbbbbbaabbbaabbbbabbbaabbbbbbabaaaabbaaabb...
output:
24882
result:
ok 1 number(s): "24882"
Test #18:
score: -100
Time Limit Exceeded
input:
bbabaaababbabbbbbbababaababaaabababaabbbaabbbabbababbbbbabbbbaaabbbbaaaaabbaaabbbabbbbaabaabbaaaabaababbbababbbbaaaaabaabaababbbbbabbbabbaaabbabbbbaabbabababababababaabbaabbaabbabaaaabaaabbbbbababbbbaaaaabaababbbbabaaaabababaaabaaaabbbbabbbbabaaaaaababbbbabaaabaaaabaaabaabaabaabaaabbabbbbabbababaaab...