Submission #1303377

#TimeUsernameProblemLanguageResultExecution timeMemory
1303377garrinPalindromic Partitions (CEOI17_palindromic)C++20
100 / 100
92 ms17216 KiB
#include <bits/stdc++.h> #define fi first #define sc second #define int long long #define pii pair<int,int> using namespace std; const int N=1e6+5; const int N2=2e5+5; const int N5=5e5+5; const int N1=1e6+5; const int inf=1e18+7; const int MOD=1e9+7; const int base=311; int n,t; int pw[N]; int ha[N],hb[N]; string s; int geta(int l,int r) { return (ha[r]-ha[l-1]*pw[r-l+1]%MOD+MOD)%MOD; } int32_t main() { //freopen("SIXCUP.inp","r",stdin); //freopen("SIXCUP.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>t; pw[0]=1; for(int i=1;i<=N-5;i++) pw[i]=(pw[i-1]*base)%MOD; while(t--) { cin>>s; n=s.size(); bool check=true; int sz=0,res=0; for(int i=1;i<=n;i++) ha[i]=(ha[i-1]*base+s[i-1])%MOD; int st=1; for(int i=1;i<=n/2;i++) { if(check==true) st=i,check=false; int ka=geta(st,i); int kb=geta(n-i+1,n-st+1); if(ka==kb) {res+=2,check=true; sz+=2*(i-st+1); if(i-st+1==n) res--; } } if(sz<n) res++; for(int i=1;i<=n;i++) { ha[i]=0; } cout<<res<<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...