Submission #1298947

#TimeUsernameProblemLanguageResultExecution timeMemory
1298947buzdiPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
33 ms1508 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int MOD = 1e9 + 7; const int BASE = 31; int n; string s; void test_case() { cin >> s; n = s.size(); int l = 0, r = n - 1, h1 = 0, h2 = 0, pbase = 1, answer = 0; while(l < r) { h1 = ((ll) h1 * BASE + (s[l] - 'a' + 1)) % MOD; h2 = (h2 + (ll) pbase * (s[r] - 'a' + 1)) % MOD; if(h1 == h2) { answer += 2; h1 = h2 = 0; pbase = 1; } else { pbase = (ll) pbase * BASE % MOD; } l++; r--; } if(l == r) { answer++; } if(l != r && h1 != 0) { answer++; } cout << answer << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) { test_case(); } 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...