# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
406508 | Pichon5 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 1 ms | 204 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>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
//"\n"
//algoritmo para calcular la cantidad de substrings diferentes
using namespace std;
const ll MOD=1e9+9;
const ll p=31;
int main()
{
int t;
string s;
cin>>t;
while(t--){
cin>>s;
ll n=s.size();
ll P[n+1];
ll h[n+2];
h[0]=0;
ll pot=1;
for(int i=0;i<n;i++){
ll x=s[i]-'a'+1;
P[i]=pot;
h[i+1]=(h[i]+x*pot)%MOD;
pot=(pot*p)%MOD;
}
int tam=1;
int izq=0,der=n-1;
int res=0;
if(n==1)res=1;
int c=10;
while(1){
if(izq==der){
res++;
break;
}
if(izq+tam-1>der-tam+1)break;
int a=(h[izq+tam]-h[izq]+MOD)%MOD;
a=(a*P[n-izq-1])%MOD;
int b=(h[der+1]-h[der-tam+1]+MOD)%MOD;
b=(b*P[(n-1)-(der-tam+1)])%MOD;
//cout<<a<<" "<<b<<endl;
if(a==b){
izq+=tam;
der-=tam;
tam=1;
res+=2;
continue;
}
if(izq+tam>=der-tam){
res++;
break;
}
tam++;
}
cout<<res<<endl;
}
return 0;
}
//https://codeforces.com/contest/911/problem/D
//https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1021
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... |