# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
707800 | guagua0407 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 316 ms | 28632 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.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=1e6+5;
ll p=27;
ll mod=(1ll<<61)-1;
ll powv[mxn];
ll hashv[mxn];
void pre(){
powv[0]=1;
for(int i=1;i<mxn;i++){
powv[i]=((__int128)powv[i-1]*p)%mod;
}
}
void genhash(string str){
for(int i=1;i<=str.length();i++){
hashv[i]=((__int128)hashv[i-1]*p%mod+str[i-1]-'a'+1)%mod;
}
}
ll cal(int l,int r){
ll ans=(hashv[r]-(__int128)hashv[l-1]*powv[r-l+1]%mod)%mod;
if(ans<0) ans+=mod;
return ans;
}
void solve(){
string str;
cin>>str;
int n=str.length();
genhash(str);
int l=1;
int ans=0;
while(l<=n/2){
int r=l;
bool tf=false;
while(r<=n/2){
if(cal(l,r)==cal(n-l+1-(r-l+1)+1,n-l+1)){
tf=true;
break;
}
r++;
}
if(tf){
ans++;
l=r+1;
}
else{
break;
}
}
ans*=2;
if(l!=n/2+1 or n&1) ans++;
cout<<ans<<'\n';
}
int main() {_
//setIO("wayne");
pre();
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
//maybe its multiset not set
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... |