Submission #161509

#TimeUsernameProblemLanguageResultExecution timeMemory
161509MinnakhmetovPalindromic Partitions (CEOI17_palindromic)C++14
100 / 100
53 ms19832 KiB
#include <bits/stdc++.h> #define ll long long #define all(aaa) aaa.begin(), aaa.end() using namespace std; const int N = 1e6 + 5, X = 997, M = 1e9 + 9; int dp[N]; ll p[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); p[0] = 1; for (int i = 1; i < N; i++) p[i] = p[i - 1] * X; int t; cin >> t; while (t--) { string s; cin >> s; int n = s.size(); int ans = 0, i = 0; bool work = true; while (work) { work = false; ll h1 = 0, h2 = 0; for (int j = 1; j * 2 <= n - i * 2; j++) { h1 = h1 * X + s[j + i - 1]; h2 = h2 + s[n - j - i] * p[j - 1]; if (h1 == h2) { i += j; ans += 2; work = true; break; } } } if (i * 2 < n) 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...