이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int longpal_partitions(char *word)
{
const int n=strlen(word);
const int prime=131;
int countedch=0;
int piececounts=0;
while(countedch*2<n)
{
int lhash=0,rhash=0,power=1;
for(int piecesize=1;true;piecesize++)
{
int l=countedch,r=n-countedch-piecesize;
if(l+piecesize-1>=r)
return piececounts+1;
if(piecesize==1)
power=1;
else
power*=prime;
lhash+=static_cast<int>(word[l+piecesize-1])*power;
rhash=static_cast<int>(word[r])+rhash*prime;
if(lhash==rhash && strncmp(word+l,word+r,piecesize)==0)
{
piececounts+=2;
countedch+=piecesize;
break;
}
}
}
return piececounts;
}
int main()
{
int n;
char word[510000];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>word;
assert(strlen(word)<=510000);
cout<<longpal_partitions(word)<<endl;
}
return 0;
}
# | 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... |