Submission #596975

#TimeUsernameProblemLanguageResultExecution timeMemory
5969751binPalindromic Partitions (CEOI17_palindromic)C++14
15 / 100
1 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int NMAX = 1e6 + 5; const ll m1 = 1e15 + 1, m2 = 1e15 + 3; int tc, n, l1, l2, r1, r2, pw1, pw2; string s; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> tc; while(tc--){ cin >> s; n = s.size(); l1 = l2 = r1 = r2 = 0; pw1 = pw2 = 1; int ans = 0, cnt = 0; for(int i = 0; i < n / 2; i++){ l1 = (l1 * 26 + s[i] - 'a') % m1; l2 = (l2 * 26 + s[i] - 'a') % m2; r1 = (r1 + pw1 * (s[n - 1 - i] - 'a')) % m1; r2 = (r2 + pw2 * (s[n - 1 - i] - 'a')) % m2; if(l1 == r1 && l2 == r2){ ans += 2; cnt = 0; l1 = l2 = r1 = r2 = 0; pw1 = pw2 = 1; } else { cnt++; pw1 = pw1 * 26 % m1; pw2 = pw2 * 26 % m2; } } if(n & 1 || cnt) ans++; 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...