# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850869 | dungz | Palindromic Partitions (CEOI17_palindromic) | C++17 | 92 ms | 20748 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 ll long long
#define endl '\n'
ll const MOD=1e9+9,base=31;
ll p[1000005];
void sol()
{
string s;
cin>>s;
s=" "+s;
int i=1,j=s.size()-1;
ll hash1=0,hash2=0;
int d=0,ans=0;
p[0]=1;
for(int i=1;i<=s.size()-1;i++)
{
p[i]=(p[i-1]*base)%MOD;
}
int flag=1;
for(int step=1;step<=s.size()/2-(s.size()%2==0?1:0);step++)
{
hash1=(hash1*base+s[i]-'a'+1)%MOD;
hash2=(hash2+(s[j]-'a'+1)*p[d])%MOD;
flag=1;
if(hash1==hash2)
{
flag=0;
hash1=0;
hash2=0;
ans+=2;
d=-1;
}
d++;
i++,j--;
}
if(s.size()%2==1) cout<<ans+flag<<endl;
else cout<<ans+1<<endl;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);
int t;
cin>>t;
while(t--)
{
sol();
}
}
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... |