Submission #972145

#TimeUsernameProblemLanguageResultExecution timeMemory
972145efedmrlrPalindromic Partitions (CEOI17_palindromic)C++17
60 / 100
26 ms8236 KiB
#include <bits/stdc++.h> #define lli long long int #define ld long double #define pb push_back #define MP make_pair #define REP(i, n) for(int i = 0; (i) < (n); (i)++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const int N = 1e5 + 5; const lli INF = 1e17; const int MOD = 1e9 + 7; const int B = 3; array<int, B> P = {31, 37, 73}; array<array<int, N>, B> pw; int add(int x, int y) { if(x + y >= MOD) return x + y - MOD; return x + y; } int subt(int x, int y) { if(x - y < 0) return x - y + MOD; return x - y; } int mult(int x, int y) { return (int)(1ll * x * y % MOD); } int fp(int x, int y) { int ret = 1; while(y > 0) { if(y & 1) { ret = mult(ret, x); } x = mult(x, x); y >>= 1; } return ret; } int n; string s; void solve() { cin >> s; n = (int)s.size(); int ans = 0; array<int, B> fr, en; REP(b, B) { fr[b] = en[b] = 0; } int len = 0; int i = 0; for(; i < (n - 1) / 2 + 1; i++) { int j = n - i - 1; REP(b, B) { fr[b] = add(mult(fr[b], P[b]), s[i] - 'a' + 1); en[b] = add(en[b], mult(s[j] - 'a' + 1, pw[b][len])); } len++; bool f = 1; REP(b, B) { if(fr[b] != en[b]) f = 0; } if(f) { ans += 2; if(i == j) ans--; len = 0; REP(b, B) { fr[b] = en[b] = 0; } } } if(len > 0) ans++; cout << ans << "\n"; } signed main() { REP(b, B) { pw[b][0] = 1; for(int i = 1; i < N; i++) { pw[b][i] = mult(pw[b][i - 1], P[b]); } } fastio(); int test = 1; cin >> test; while(test--) { 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...