Submission #586295

#TimeUsernameProblemLanguageResultExecution timeMemory
586295lalala56Palindromic Partitions (CEOI17_palindromic)C++17
0 / 100
0 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const ll mod=1e9+7,ba=9907; const int N=1e6+9; ll h[N],p[N]; int n,res; string s; ll hass(int l,int r){ return (h[r]-h[l-1]*p[r-l+1]+mod*mod)%mod; } void giai(){ cin>>s; n=s.length(); s=' '+s; p[0]=1; for(int i=1;i<=n;i++)p[i]=(p[i-1]*ba)%mod; for(int i=1;i<=n;i++){ h[i]=(h[i-1]*ba+int(s[i])-'a'+1)%mod; } res=1; int p=1,q=n; //cout<<n<<" "<<s<<" "; for(int i=1;i<=n/2;i++){ if(hass(p,i)==hass(n-i+1,q)){ //cout<<i<<endl; p=i+1; q=n-i; res+=2; } } cout<<res<<'\n'; } int main(){ // freopen("solve.inp","r",stdin); // freopen("solve.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin>>t; while(t--)giai(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...