Submission #1092816

#TimeUsernameProblemLanguageResultExecution timeMemory
1092816owoovoPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
433 ms20776 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second using namespace std; const ll p=1e9+7; const ll c=47; ll hah[1000010]; ll pw(ll a,ll b){ ll ans=1; while(b){ if(b&1)ans*=a,ans%=p; b>>=1; a*=a; a%=p; } return ans; } ll hh(int l,int r){ return ((hah[r]-hah[l-1]*pw(c,r-l+1)%p)%p+p)%p; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--){ string s; cin>>s; int n=s.size(); for(int i=1;i<=n;i++){ char ch=s[i-1]; ll val=int(ch-'a')+3; hah[i]=hah[i-1]*c+val; hah[i]%=p; } int l=1,r=n,i=0,ans=0; while(l<=r){ while(l+i<=r&&hh(l,l+i)!=hh(r-i,r)){ i++; } ans+=2; if(l+i==r)ans--; l=l+i+1,r=r-i-1,i=0; } cout<<ans<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...