QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#445504 | #8521. Pattern Search II | ucup-team3695# | TL | 1591ms | 8236kb | C++20 | 1.6kb | 2024-06-16 03:12:07 | 2024-06-16 03:12:08 |
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};
}
unordered_map<int, int> DP, EP;
DP.emplace(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;
}
if (i >= LIM)
continue;
char ch = s[j];
EP[i + 1] = max(EP[i + 1], j + (ch == B[i]));
if (J[i].second)
EP[J[i].first] = max(EP[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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7572kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 7716kb
input:
a
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 3ms
memory: 7672kb
input:
b
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 7716kb
input:
aa
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 2ms
memory: 7540kb
input:
bb
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 3ms
memory: 7680kb
input:
ab
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 7588kb
input:
ba
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 0ms
memory: 7712kb
input:
bbba
output:
7
result:
ok 1 number(s): "7"
Test #9:
score: 0
Accepted
time: 0ms
memory: 7628kb
input:
abbbbbbbab
output:
20
result:
ok 1 number(s): "20"
Test #10:
score: 0
Accepted
time: 0ms
memory: 7820kb
input:
abbbbabbbabbbabbabaabbabb
output:
43
result:
ok 1 number(s): "43"
Test #11:
score: 0
Accepted
time: 2ms
memory: 7704kb
input:
bbbaabaabbbaabababbbabaaabaaabbbaaaabaabaaaaabbabbbababbabaaba
output:
94
result:
ok 1 number(s): "94"
Test #12:
score: 0
Accepted
time: 3ms
memory: 7732kb
input:
ababaaabbaaaabaaaaabbabbbababaabaabbabbabaaaabbbabbaaaabaaaabbbabaaaaabbbbbbbbaabaabaabbbbbbabbaabaaaabbbabbbaaabaaabaababaabbbbbbbbaabababaabbaabbbaaaaabb
output:
245
result:
ok 1 number(s): "245"
Test #13:
score: 0
Accepted
time: 4ms
memory: 7652kb
input:
aaaabbbbaaaaababababaaabbbbbbababbaaaaabaaaaaabababbaabbbabbabbbbabbbabaabaaaabababaabbbaaaaabbbabaabaaaababaabbaaabbbaaaabbbaabbaaabbabbbabbabbaababbbbabbbbbbabbaaabbaabbbbbbabababbaaababbaaaaaaabaabbaabbabbbaaaaaaaaaababbaaaabaabbbabbbaabbabbbaabaaaaaabaababaaaababaaaaaababbaaaaaabaabbaabbbbbbaaba...
output:
625
result:
ok 1 number(s): "625"
Test #14:
score: 0
Accepted
time: 38ms
memory: 7660kb
input:
aabaababbbbbbbbaabaaaaaabbbaababbabbabbaabbaaaaabaaaabbbbababbaabaaaaaabbbbabbbbbbbabbbaababbbbbbabaaababbaabaaaabbaababbbaaabbabababbbbbabbbaaaaaabbaabbbbabbabbaaaaaabababbabbbbabaabbbbbbbbaaabababbbbbbbaaababbbbbbabbbbabbaaabbbbaaabaaabbaabaabbaaaabababbabbabababbbaabbbbbabaaabbbabbbababbaababbbba...
output:
1608
result:
ok 1 number(s): "1608"
Test #15:
score: 0
Accepted
time: 228ms
memory: 8012kb
input:
aaababbbabbaabbbababbaaababaabbbbbabbbabbbabbabbaabbabbabaaabaabbbbbabababbbabaaaabaaababbabaaaabababbaabbaaaaaababaabababbbaaaabbababbbaaaaabababbaaaaabaabbbbbbaabaaaabbbaaababaabbbabaabaaababbbaaaaaabbbbbbbabbbabbaaaababbababaababaabbbbbaaaaabbababbbaabaabbabbaabbbbabaaabbababaaaabbbabaaabaabbbbab...
output:
3954
result:
ok 1 number(s): "3954"
Test #16:
score: 0
Accepted
time: 1591ms
memory: 8236kb
input:
aaabbbbabaaabbabbaabbabbbbbbbaaabbaaaaabbbbbaaaabbbaaabbabbaabaabbbaabaababaabbbababbbbbbabbababbbbabaaababbbaaabbabbbaabbbbbbbbbbabbbbbabbabbbbabbbbbbbaabaaaaaabbbaaabaabaaaaabbabbaaabbababaaaaaababbbabaabbbaabaaabaabbabaaaaababaaabbaabaababbaaabaabbaabbbbaababbaabaaabababbbbbabbbbababbbbbbaabbabab...
output:
10033
result:
ok 1 number(s): "10033"
Test #17:
score: -100
Time Limit Exceeded
input:
aabbbbbabababbbababaaabaabbbbbbaaababaabaababbbbbaabaabababaabbbbbbaabbbababbbbbbbbbbabababbabbaaaabaaaaabbabbbabbaaaaababababaaabbbbbbbabbbbbbbbaaabbbaaababbaaaaaabaabbaababbbabaaabbbaabbabababbaaaababbbabbbabaaaaabbbabbbabbaaaabababbbbbbaabbbaaaabbabbabbabbbbbbbaabbbaabbbbabbbaabbbbbbabaaaabbaaabb...