# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
939169 | vjudge1 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 6 ms | 8028 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 int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e6+5,mod=1e9+7,tt=13;
int pw[N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int t;
cin>>t;
pw[0]=1;
for(int i=1;i<N;i++){
pw[i]=pw[i-1]*tt;
pw[i]%=mod;
}
while(t--){
string s;
cin>>s;
s=" "+s;
vector <int> h(s.size());
for(int i=1;i<s.size();i++){
h[i]=h[i-1]*tt+(s[i]-'a'+1);
h[i]%=mod;
}
int st1=1,end2=s.size()-1;
int end1=1,st2=s.size()-1;
int h1=0,h2=0;
int ans=0;
while(end1<st2){
h1=(h[end1]-h[st1-1]*pw[end1-st1+1])%mod;
h2=(h[end2]-h[st2-1]*pw[end2-st2+1])%mod;
if(h1==h2){
end1++;
st1=end1;
st2--;
end2=st2;
ans+=2;
}
else{
st2--;
end1++;
}
}
if(st1<=end2)ans++;
cout<<ans<<"\n";
}
}
/*
*/
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... |