QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#482919 | #793. Palindromic Partitions | fryan# | 100 ✓ | 175ms | 30004kb | C++20 | 1.5kb | 2024-07-18 01:45:31 | 2024-07-18 01:45:31 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod=998244353;
const int p=29;
const int mxn=1e6+1;
int ksm(int a, int b=mod-2) {
int res=1,aux=a;
for (int i=1; i<=b; i*=2) {
if (i&b) {res=res*aux%mod;}
aux=aux*aux%mod;
}
return res;
}
int pw[mxn], ipw[mxn];
int n, hv[mxn];
int hashval(int l, int r) {
int h = (hv[r+1]-hv[l]+mod)%mod;
return (h*ipw[l])%mod;
}
int svf(int L, int R) {
if (L==R+1) return 0;
if (L>R) return -1;
for (int le = 0; le<=(R-L); le++) {
if (hashval(L,L+le)==hashval(R-le,R)) {
return 2+svf(L+le+1,R-le-1);
}
}
assert(0);
}
void solve() {
string s; cin>>s;
n=sz(s);
for (int i=0; i<n; i++) {
hv[i+1] = (hv[i] + pw[i]*(s[i]-'a'+1))%mod;
}
cout<<svf(0,n-1)<<"\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
pw[0]=1; ipw[0]=1;
for (int i=1; i<mxn; i++) {
pw[i]=pw[i-1]*p%mod;
ipw[i]=ksm(pw[i]);
}
int t; cin>>t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 115ms
memory: 19328kb
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: 115ms
memory: 21264kb
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: 111ms
memory: 19688kb
input:
5 abba aabaab x aa ab
output:
4 2 1 2 1
result:
ok 5 lines
Test #4:
score: 0
Accepted
time: 111ms
memory: 20284kb
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: 115ms
memory: 19656kb
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: 99ms
memory: 20720kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
300 299 2 3 2 30 150 100 300 11
result:
ok 10 lines
Test #7:
score: 0
Accepted
time: 115ms
memory: 20580kb
input:
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaababbbababbababbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb aaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
3 9 7 2 177 256
result:
ok 6 lines
Test #8:
score: 0
Accepted
time: 111ms
memory: 19528kb
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: 104ms
memory: 20096kb
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: 112ms
memory: 21436kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
10000 9999 2 3 2 100 5000 3333 9996 495
result:
ok 10 lines
Test #11:
score: 0
Accepted
time: 111ms
memory: 21400kb
input:
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
3 9 18 2 5169 4096
result:
ok 6 lines
Test #12:
score: 0
Accepted
time: 100ms
memory: 21172kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaa...
output:
258 282 116 109 287 192 167 251 148 146
result:
ok 10 lines
Test #13:
score: 0
Accepted
time: 115ms
memory: 19584kb
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: 175ms
memory: 30004kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1000000 999999 2 3 2 1000 500000 333333 999996 48937
result:
ok 10 lines
Test #15:
score: 0
Accepted
time: 146ms
memory: 29360kb
input:
6 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
3 3 7 2 635623 262144
result:
ok 6 lines
Test #16:
score: 0
Accepted
time: 164ms
memory: 29592kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1777 1925 1110 1151 2733 2540 2190 2760 1152 2229
result:
ok 10 lines
Test #17:
score: 0
Accepted
time: 154ms
memory: 26200kb
input:
10 abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabb...
output:
262144 262144 262144 262144 262144 262144 262144 262144 262144 262144
result:
ok 10 lines