QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#242960 | #793. Palindromic Partitions | Camillus# | 100 ✓ | 100ms | 13964kb | C++20 | 1.8kb | 2023-11-07 19:11:01 | 2024-07-04 02:23:07 |
Judging History
answer
#include "bits/stdc++.h"
using ll = long long;
using namespace std;
struct hasher {
static constexpr int mod = 1'000'000'007;
static constexpr int p = 43;
vector<int> pow;
vector<int> val;
int n;
hasher(string s) {
n = (int)s.size();
pow.resize(n + 1);
pow[0] = 1;
for (int i = 1; i <= n; i++) {
pow[i] = 1ll * pow[i - 1] * p % mod;
}
val.resize(n + 1);
for (int i = 1; i <= n; i++) {
val[i] = (ll)(s[i - 1] - 'a' + 1) * pow[i] % mod;
val[i] += val[i - 1];
if (val[i] >= mod) {
val[i] -= mod;
}
}
}
int get(int l, int r) const {
int res = val[r + 1] - val[l] + mod;
if (res >= mod) {
res -= mod;
}
return 1ll * res * pow[n - r - 1] % mod;
}
};
void solve() {
string s;
cin >> s;
hasher h(s);
int n = (int)s.size();
int l = 0, r = n - 1;
int ans = 0;
while (l <= r) {
bool ok = false;
for (int k = 1; k < r - l + 1; k++) {
if (l + k - 1 < r - k + 1 && h.get(l, l + k - 1) == h.get(r - k + 1, r)) {
l += k;
r -= k;
ans += 2;
ok = true;
break;
}
}
if (!ok) {
ans += 1;
break;
}
}
cout << ans << '\n';
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 0ms
memory: 3584kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaabaaaaaaaaaaaaaab aaaaaaaaaaaaabxaaaaaaaaaaaaab baaaaaaaaaaaaaabaaaaaaaaaaaaaa aabbaabbaabbaaaaaaaabbaabbaabb ababababababababababababababab abcabcabcabcabcabcabcabcabcabc abcabcabcabcabccbacbacbacbacba qntshryhcojkqnlmqeob...
output:
30 29 2 3 2 12 15 10 30 3
result:
ok 10 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
10 aaabbbbaabbbbbbbaaaaabbb aaaababbbaabbabbbaaaaababbb aaabbbbaaaaaaaabbbba aaaaaaabbbbbbbaaaaaaabbbbbbb babbababbabbababbabab abbabaabbaababba bonobo palindrome deemed level
output:
10 5 10 2 17 16 3 1 5 5
result:
ok 10 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
5 abba aabaab x aa ab
output:
4 2 1 2 1
result:
ok 5 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
10 aabbaabbaabbaaaaaaaabbaabbaabb aabbaabbaabbaaaaabbaabbaabb aabbaabbaabbaaaaabbaabbaabb aabbaabbaabbaaaaaaaabbaabbaabb aabbaabbaabbaaaaaaaabbaabbaabb aabbaabbaabbaaaaabbaabbaabb aabbaabbaabbaaaaaaaabbaabbaabb aabbaabbaabbaaaaaabbaabbaabb aabbaabbaabbaaaaaaabbaabbaabb aabbaabbaabbaaaaaaabbaabbaabb
output:
12 9 9 12 12 9 12 10 11 11
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 abbabaabbaababba abbabaabbaababba abbabaabbaababba abbabaabbaababba abbabaabbaababba abbabaabbaababba abbabaabbaababba abbabaabbaababba abbabaabbaababba abbabaabbaababba
output:
16 16 16 16 16 16 16 16 16 16
result:
ok 10 lines
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 20
Accepted
time: 0ms
memory: 3588kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
300 299 2 3 2 30 150 100 300 11
result:
ok 10 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaababbbababbababbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb aaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
3 9 7 2 177 256
result:
ok 6 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
10 aaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbb aaaaaaaab...
output:
47 32 31 33 22 46 46 24 34 46
result:
ok 10 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
10 abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababba abbabaabbaababbabaababbaabbabaabbaababba...
output:
256 256 256 256 256 256 256 256 256 256
result:
ok 10 lines
Subtask #3:
score: 25
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #10:
score: 25
Accepted
time: 1ms
memory: 3724kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
10000 9999 2 3 2 100 5000 3333 9996 495
result:
ok 10 lines
Test #11:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
3 9 18 2 5169 4096
result:
ok 6 lines
Test #12:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaa...
output:
258 282 116 109 287 192 167 251 148 146
result:
ok 10 lines
Test #13:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
10 abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabb...
output:
4096 4096 4096 4096 4096 4096 4096 4096 4096 4096
result:
ok 10 lines
Subtask #4:
score: 40
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #14:
score: 40
Accepted
time: 100ms
memory: 13928kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1000000 999999 2 3 2 1000 500000 333333 999996 48937
result:
ok 10 lines
Test #15:
score: 0
Accepted
time: 50ms
memory: 13616kb
input:
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
3 3 7 2 635623 262144
result:
ok 6 lines
Test #16:
score: 0
Accepted
time: 86ms
memory: 13964kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1777 1925 1110 1151 2733 2540 2190 2760 1152 2229
result:
ok 10 lines
Test #17:
score: 0
Accepted
time: 55ms
memory: 8884kb
input:
10 abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabb...
output:
262144 262144 262144 262144 262144 262144 262144 262144 262144 262144
result:
ok 10 lines