Submission #916710

#TimeUsernameProblemLanguageResultExecution timeMemory
916710vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
60 / 100
9 ms1368 KiB
#include <bits/stdc++.h> using namespace std; unsigned int longpal_partitions(char *word) { const unsigned int n=strlen(word); const unsigned int prime=131; unsigned int countedch=0; unsigned int piececounts=0; while(countedch*2<n) { unsigned int lhash=0,rhash=0,power=1; for(unsigned int piecesize=1;true;piecesize++) { unsigned 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<unsigned int>(word[l+piecesize-1])*power; rhash=static_cast<unsigned int>(word[r])+rhash*prime; if(lhash==rhash && strncmp(word+l,word+r,piecesize)==0) { piececounts+=2; countedch+=piecesize; break; } } } return piececounts; } int main() { unsigned int n; char word[510000]; cin>>n; for(unsigned int i=0;i<n;i++) { cin>>word; assert(strlen(word)<=510000); cout<<longpal_partitions(word)<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...