# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129976 | TadijaSebez | Palindromic Partitions (CEOI17_palindromic) | C++11 | 244 ms | 22812 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 <stdio.h>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
const int mod=998244353;
const int N=1000050;
int hs[N],po[N],ip[N];
int pow(int x, int k)
{
int ret=1;
for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;
return ret;
}
void preprocess()
{
int i;
po[0]=1;
for(i=1;i<N;i++) po[i]=(ll)po[i-1]*26%mod;
int mul=pow(26,mod-2);
ip[0]=1;
for(i=1;i<N;i++) ip[i]=(ll)ip[i-1]*mul%mod;
}
char s[N];
void Build(int n)
{
int i;
for(i=1;i<=n;i++)
{
hs[i]=(ll)hs[i-1]*26%mod+(s[i]-'a'+1);
hs[i]%=mod;
}
}
int GetHash(int l, int r)
{
int ret=hs[r]-(ll)hs[l-1]*po[r-l+1]%mod;
if(ret<0) ret+=mod;
return ret;
}
bool Compare(int l1, int r1, int l2, int r2)
{
return GetHash(l1,r1)==GetHash(l2,r2);
}
int main()
{
preprocess();
int t;
scanf("%i",&t);
while(t--)
{
scanf("%s",s+1);
int n=strlen(s+1);
Build(n);
int sol=0,i,j=1;
for(i=1;i<=n-j+1;i++)
{
if(Compare(j,i,n-i+1,n-j+1))
{
sol++;
if(i!=n-j+1) sol++;
//printf("%i %i\n",j,i);
j=i+1;
}
}
printf("%i\n",sol);
for(i=1;i<=n;i++) s[i]=0;
}
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... |