Submission #710615

#TimeUsernameProblemLanguageResultExecution timeMemory
710615groshiPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
32 ms20548 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int pierw=31; int potega[2000000]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; potega[0]=1; for(int i=1;i<=1000000;i++) potega[i]=potega[i-1]*pierw; for(int i=1;i<=n;i++) { string s; cin>>s; int l=0,r=s.length()-1; int jeden=0,dwa=0; int wynik=1; int dl=0; while(l<r) { jeden*=pierw; jeden+=s[l]-'a'; dwa+=potega[dl]*(s[r]-'a'); if(jeden==dwa) { if(r-1==l) wynik--; wynik+=2; dl=-1; jeden=0,dwa=0; } l++; r--; dl++; } cout<<wynik<<"\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...