# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
670362 | Mohammad_Parsa | Palindromic Partitions (CEOI17_palindromic) | C++17 | 10006 ms | 2688 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.
/* in the name of allah */
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define mk make_pair
typedef long long ll;
const ll N=1e6+7,mod=1e13+3,mab=27;
int dp[N];
int main(){
ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0);
int q;
cin>>q;
while(q--){
string s;
cin>>s;
int k=s.size()/2-1,j=k+1;
if(s.size()%2==0){
dp[0]=0;
}
else{
dp[0]=1;j++;
}
for(int i=1;i<=s.size()/2;i++){
ll h1=0,h2=0,t=1;
dp[i]=1;
int g=0;
for(int h=0;h<=s.size()/2-1-k;h++){
h1=h1*mab%mod;h1=(h1+s[k+h]-'a')%mod;
h2=(h2+(s[j-h]-'a')*t)%mod;t=t*mab%mod;
if(h1==h2){
if(dp[i-h-1]+2>dp[i]){
if(g>0) cout<<"F"<<endl;
g++;
}
dp[i]=max(dp[i],dp[i-h-1]+2);
}
}
k--;j++;
}
cout<<dp[s.size()/2]<<endl;
}
}
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... |