# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199669 | algorithm16 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 557 ms | 27952 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<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int llint;
llint h[1000005],p=31337,pot[1000005];
llint get(int a,int b) {
llint ret=h[b];
if(a==0) return ret;
return ret-h[a-1]*pot[b-a+1];
}
int main()
{
int t;
cin >> t;
for(int i=0;i<t;i++) {
string s;
cin >> s;
h[0]=s[0]-'a';
pot[0]=1;
pot[1]=p;
for(int j=1;j<s.size();j++) {
h[j]=h[j-1]*p+s[j]-'a';
pot[j+1]=pot[j]*p;
}
int x1=0,x2=0,y=s.size()-1,cnt=0;
while(x2<y) {
if(get(x1,x2)==get(y-(x2-x1),y)) {
cnt+=2;
y-=(x2-x1)+1;
x1=x2+1;
x2+=1;
}
else x2+=1;
}
if(x2<=y) cnt+=1;
cout << cnt << "\n";
}
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... |