# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154316 | 2019-09-20T12:45:18 Z | arnold518 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 239 ms | 34644 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; const ll MOD = 1e9+7; const ll P = 31; int TC, N, ans; char S[MAXN+10]; ll ppow[MAXN+10], ipow[MAXN+10], H[MAXN+10]; ll mypow(ll x, ll y) { if(y==0) return 1; if(y%2) return mypow(x, y-1)*x%MOD; ll t=mypow(x, y/2); return t*t%MOD; } ll calc(int l, int r) { ll t=H[r]-H[l-1]; t%=MOD; if(t<0) t+=MOD; t*=ipow[l]; t%=MOD; return t; } int main() { int i, j; ppow[0]=1; ipow[0]=1; ipow[1]=mypow(P, MOD-2); for(i=1; i<=MAXN; i++) ppow[i]=ppow[i-1]*P%MOD; for(i=2; i<=MAXN; i++) ipow[i]=ipow[i-1]*ipow[1]%MOD; scanf("%d", &TC); while(TC--) { scanf("%s", S+1); N=strlen(S+1); ans=0; for(i=1; i<=N; i++) H[i]=(S[i]-'a'+1)*ppow[i]%MOD; for(i=1; i<=N; i++) H[i]=(H[i-1]+H[i])%MOD; int it=1; for(i=1; i<=N/2; i++) if(calc(it, i)==calc(N-i+1, N-it+1)) { //printf("!%d\n", i); ans+=2; it=i+1; } if(N%2 || it!=N/2+1) ans++; printf("%d\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 15992 KB | Output is correct |
2 | Correct | 26 ms | 15912 KB | Output is correct |
3 | Correct | 26 ms | 15992 KB | Output is correct |
4 | Correct | 26 ms | 15992 KB | Output is correct |
5 | Correct | 29 ms | 15992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 15992 KB | Output is correct |
2 | Correct | 26 ms | 15912 KB | Output is correct |
3 | Correct | 26 ms | 15992 KB | Output is correct |
4 | Correct | 26 ms | 15992 KB | Output is correct |
5 | Correct | 29 ms | 15992 KB | Output is correct |
6 | Correct | 26 ms | 15992 KB | Output is correct |
7 | Correct | 27 ms | 15996 KB | Output is correct |
8 | Correct | 26 ms | 15992 KB | Output is correct |
9 | Correct | 26 ms | 15992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 15992 KB | Output is correct |
2 | Correct | 26 ms | 15912 KB | Output is correct |
3 | Correct | 26 ms | 15992 KB | Output is correct |
4 | Correct | 26 ms | 15992 KB | Output is correct |
5 | Correct | 29 ms | 15992 KB | Output is correct |
6 | Correct | 26 ms | 15992 KB | Output is correct |
7 | Correct | 27 ms | 15996 KB | Output is correct |
8 | Correct | 26 ms | 15992 KB | Output is correct |
9 | Correct | 26 ms | 15992 KB | Output is correct |
10 | Correct | 28 ms | 16220 KB | Output is correct |
11 | Correct | 28 ms | 16088 KB | Output is correct |
12 | Correct | 28 ms | 16164 KB | Output is correct |
13 | Correct | 28 ms | 16108 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 15992 KB | Output is correct |
2 | Correct | 26 ms | 15912 KB | Output is correct |
3 | Correct | 26 ms | 15992 KB | Output is correct |
4 | Correct | 26 ms | 15992 KB | Output is correct |
5 | Correct | 29 ms | 15992 KB | Output is correct |
6 | Correct | 26 ms | 15992 KB | Output is correct |
7 | Correct | 27 ms | 15996 KB | Output is correct |
8 | Correct | 26 ms | 15992 KB | Output is correct |
9 | Correct | 26 ms | 15992 KB | Output is correct |
10 | Correct | 28 ms | 16220 KB | Output is correct |
11 | Correct | 28 ms | 16088 KB | Output is correct |
12 | Correct | 28 ms | 16164 KB | Output is correct |
13 | Correct | 28 ms | 16108 KB | Output is correct |
14 | Correct | 239 ms | 34644 KB | Output is correct |
15 | Correct | 145 ms | 29888 KB | Output is correct |
16 | Correct | 219 ms | 34012 KB | Output is correct |
17 | Correct | 133 ms | 25848 KB | Output is correct |