# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994970 | doducanh | Palindromic Partitions (CEOI17_palindromic) | C++14 | 54 ms | 12972 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int maxn=1e6+7;
//int p[maxn];
//int h[maxn];
string s;
int t;
//int get(int l,int r)
//{
// return (h[r]-(h[l-1]*p[r-l+1]%mod)+mod)%mod;
//}
void sol()
{
cin>>s;
int n=s.size();
s=" "+s;
int found=0;
int start=1;
int ans=0;
while(found!=-1){
int left=0;
int right=0;
found=-1;
for(int i=start,p=1;i<=n/2;i++,p=(p*32)%mod){
left=((left*32)%mod+(s[i]-'a'+1))%mod;
right=(right+(p*(s[n-i+1]-'a'+1))%mod)%mod;
// cout<<left<<" "<<right<<" "<<s[i]<<"\n";
if(left==right){
found=i;
start=found+1;
break;
}
}
if(found!=-1){
ans+=2;
}
}
if((start-1)*2==n)cout<<ans<<"\n";
else cout<<ans+1<<"\n";
}
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
sol();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |