Submission #155122

#TimeUsernameProblemLanguageResultExecution timeMemory
155122lycPalindromic Partitions (CEOI17_palindromic)C++14
100 / 100
86 ms15072 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef pair<ii, int> ri3; #define mp make_pair #define pb push_back #define fi first #define sc second #define SZ(x) (int)(x).size() #define ALL(x) begin(x), end(x) #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define RFOR(i, a, b) for (int i = a; i >= b; --i) const int P = 1e9 + 11; const int Q = 4001; const int MAXN = 1e6+5; int T, N; string S; int F[MAXN]; int solve(int s, int e) { //cout << "solve " << s << " " << e << endl; if (s > e) return 0; int h1 = 0, h2 = 0; for (int l = 0; s+l < e-l; ++l) { h1 = (((ll)h1 * Q % P) + (S[s+l]-'a')) % P; h2 = ((ll)h2 + (((ll)(S[e-l]-'a')*F[l]) % P)) % P; if (h1 == h2) return solve(s+l+1, e-l-1) + 2; } return 1; } int main() { //freopen("in.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); F[0] = 1; FOR(i,1,MAXN-1) F[i] = (ll)F[i-1] * Q % P; cin >> T; while(T--){ cin >> S; N = S.length(); cout << solve(0,N-1) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...