Submission #1085654

#TimeUsernameProblemLanguageResultExecution timeMemory
1085654juicyPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
27 ms20660 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif using ull = unsigned long long; const int N = 1e6 + 5, B = 331; ull pw[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); pw[0] = 1; for (int i = 1; i < N; ++i) { pw[i] = pw[i - 1] * B; } int t; cin >> t; while (t--) { string s; cin >> s; int n = s.size(), res = 0, l, r, len; ull a = 0, b = 0; for (l = 0, r = n - 1, len = 0; l < r; ++l, --r) { a = a * B + s[l] - 'a' + 1; b = (s[r] - 'a' + 1) * pw[len] + b; if (a == b) { a = b = len = 0; res += 2; } else { ++len; } } cout << res + (n & 1 || len) << "\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...