Submission #667183

#TimeUsernameProblemLanguageResultExecution timeMemory
667183ShahradPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
108 ms28524 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl '\n' #define pb push_back #define mk make_pair #define sz size() #define F first #define S second #define all(x) x.begin(), x.end() #define kill(x) return cout << x << endl, void(); #define int ll #define pii pair <int, int> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2") const int N = 1e6 + 5; const int MOD = 998244353, INF = 2e9, sq = 450; int ps[N], pw[N]; int mab = 27; int hsh (int l, int r) { return (ps[r] - (l == 0 ? 0 : ps[l - 1]) * pw[r - l + 1] % MOD + MOD) % MOD; } void Solve () { string s; cin >> s; int n = s.sz, l = 0, ans = 0; ps[0] = s[0] - 'a' + 1; for (int i = 1; i < n; i++) ps[i] = (ps[i - 1] * mab + (s[i] - 'a' + 1)) % MOD; for (int r = l; r < n - l; r++) { if (hsh (l, r) == hsh (n - r - 1, n - l - 1)) { ans += 2; if (r == n - l - 1) ans--; l = r + 1; } } cout << ans << endl; } int32_t main () { pw[0] = 1; for (int i = 1; i < N; i++) pw[i] = pw[i - 1] * mab % MOD; ios::sync_with_stdio (0), cin.tie (0), cout.tie (0); int tt = 1; cin >> tt; while (tt--) Solve (); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...