Submission #670381

#TimeUsernameProblemLanguageResultExecution timeMemory
670381Mohammad_ParsaPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
56 ms11780 KiB
/* in the name of allah */ #include<bits/stdc++.h> using namespace std; //#define endl '\n' #define pb push_back #define F first #define S second #define mk make_pair typedef long long ll; const ll N=1e6+7,mod=1e13+3,mab=27; int main(){ ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0); int q; cin>>q; while(q--){ string s; cin>>s; ll h1=0,h2=0,t=1; int j=s.size()-1,sz=s.size(); int ans=0; for(int h=0;h<=sz/2-1;h++){ //cout<<sz/2-1<<endl; h1=h1*mab%mod;h1=(h1+s[h]-'a'+1)%mod; h2=(h2+(s[j-h]-'a'+1)*t)%mod;t=t*mab%mod; if(h1==h2){ ans+=2; t=1;h1=0;h2=0; } } if(h1!=0 || s.size()%2==1)ans++; cout<<ans<<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...