Submission #1103894

#TimeUsernameProblemLanguageResultExecution timeMemory
1103894ezzzayPalindromic Partitions (CEOI17_palindromic)C++14
100 / 100
173 ms3296 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back vector<int>ans; const int mod=1e9+5; const int modd=31; void fun(){ string s; cin>>s; int n=s.size(); int a=0,b=0; int x=-1; int p=0; int mlt=1; for(int i=0;i<n/2;i++){ a=(a*modd+s[i])%mod; b=(s[n-i-1]*mlt+b)%mod; mlt=(mlt*modd)%mod; if(a==b){ x=i; a=0,b=0; p+=2; mlt=1; } } if(n%2 or x<n/2-1)p++; ans.pb(p); } signed main(){ int t; cin>>t; while(t--)fun(); for(auto a:ans)cout<<a<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...