# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168207 | 2019-12-12T02:35:00 Z | mhy908 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 480 ms | 11136 KB |
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define F first #define S second using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; const LL mod=1000000007; int t; char str[1000010]; LL power(LL a, LL b){ if(!b)return 1; LL ret=power(a, b/2); return b%2?ret*ret%mod*a%mod:ret*ret%mod; } int main() { scanf("%d", &t); for(int u=1; u<=t; u++){ memset(str, 0, sizeof(str)); scanf("%s", str+1); int ans=0; int re=strlen(str+1), fr=1; bool ch=true; while(1){ LL hash1=0, hash2=0; for(int i=0; fr+i<re-i; i++){ hash1*=997; hash1+=(LL)(str[fr+i]-'a'+1); hash1%=mod; hash2+=(LL)(str[re-i]-'a'+1)*power(997LL, (LL)i); hash2%=mod; if(hash1==hash2){ bool flag=true; for(int j=0; j<=i; j++){ if(str[fr+j]!=str[re-i+j]){ flag=false; break; } } if(flag){ fr+=i+1; re-=i+1; ans+=2; if(fr-1==re)ch=false; break; } } if(fr+i+1>=re-i-1){ fr+=i+1; re-=i+1; } } if(fr>=re&&ch){ ans++; break; } if(fr>=re)break; } printf("%d\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 3 ms | 1272 KB | Output is correct |
3 | Correct | 3 ms | 1272 KB | Output is correct |
4 | Correct | 3 ms | 1300 KB | Output is correct |
5 | Correct | 3 ms | 1272 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 3 ms | 1272 KB | Output is correct |
3 | Correct | 3 ms | 1272 KB | Output is correct |
4 | Correct | 3 ms | 1300 KB | Output is correct |
5 | Correct | 3 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1272 KB | Output is correct |
7 | Correct | 3 ms | 1272 KB | Output is correct |
8 | Correct | 3 ms | 1272 KB | Output is correct |
9 | Correct | 4 ms | 1272 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 3 ms | 1272 KB | Output is correct |
3 | Correct | 3 ms | 1272 KB | Output is correct |
4 | Correct | 3 ms | 1300 KB | Output is correct |
5 | Correct | 3 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1272 KB | Output is correct |
7 | Correct | 3 ms | 1272 KB | Output is correct |
8 | Correct | 3 ms | 1272 KB | Output is correct |
9 | Correct | 4 ms | 1272 KB | Output is correct |
10 | Correct | 6 ms | 1400 KB | Output is correct |
11 | Correct | 6 ms | 1400 KB | Output is correct |
12 | Correct | 6 ms | 1400 KB | Output is correct |
13 | Correct | 4 ms | 1400 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | Output is correct |
2 | Correct | 3 ms | 1272 KB | Output is correct |
3 | Correct | 3 ms | 1272 KB | Output is correct |
4 | Correct | 3 ms | 1300 KB | Output is correct |
5 | Correct | 3 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1272 KB | Output is correct |
7 | Correct | 3 ms | 1272 KB | Output is correct |
8 | Correct | 3 ms | 1272 KB | Output is correct |
9 | Correct | 4 ms | 1272 KB | Output is correct |
10 | Correct | 6 ms | 1400 KB | Output is correct |
11 | Correct | 6 ms | 1400 KB | Output is correct |
12 | Correct | 6 ms | 1400 KB | Output is correct |
13 | Correct | 4 ms | 1400 KB | Output is correct |
14 | Correct | 426 ms | 11136 KB | Output is correct |
15 | Correct | 411 ms | 6520 KB | Output is correct |
16 | Correct | 480 ms | 10476 KB | Output is correct |
17 | Correct | 50 ms | 6520 KB | Output is correct |