제출 #795325

#제출 시각아이디문제언어결과실행 시간메모리
795325cig32Palindromic Partitions (CEOI17_palindromic)C++17
100 / 100
380 ms35552 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int MAXN = 3e5 + 10; const int MOD = 1e9 + 7; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } //untested struct hash_string { const int fac = 2017; const int MOD = 1734232211; // prime! vector<int> pau, ps; // all indices 0-based int n; void init(string s) { n = s.size(); pau.push_back(1); for(int i=1; i<=n; i++) { pau.push_back((pau[i-1] * fac) % MOD); } ps.push_back(s[0]); for(int i=1; i<n; i++) { ps.push_back((ps[i-1] * fac + s[i]) % MOD); } } int eval(int l, int r) { return (ps[r] - (l == 0 ? 0 : (ps[l-1] * pau[r-l+1]) % MOD) + MOD) % MOD; } }; void solve(int tc) { hash_string hst; string bruh; cin >> bruh; hst.init(bruh); int l = 0, r = bruh.size() - 1; int c = 0, ans = 1; while(l <= r) { bool bad = 1; for(int i=1; i<=(r-l+1)/2; i++) { if(hst.eval(l, l+i-1) == hst.eval(r-i+1, r)) { c += 2, l += i, r -= i; ans = max(ans, c + (l <= r)); bad = 0; break; } } if(bad) break; } cout << ans << "\n"; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; cin >> t; for(int i=1; i<=t; i++) solve(i); } // 勿忘初衷
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...