Submission #585635

#TimeUsernameProblemLanguageResultExecution timeMemory
585635amunduzbaevPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
140 ms11708 KiB
#include "bits/stdc++.h" using namespace std; #define ar array typedef int64_t ll; const int N = 1e4 + 5; const int P = 167; const int mod = 1e9 + 7; void solve(){ string s; cin >> s; int n = s.size(); s = "#" + s; int h[n + 1] {}, pw[n + 1]; pw[0] = 1; for(int i=1;i<=n;i++){ h[i] = (h[i - 1] * 1ll * P + s[i] - 'a') % mod; pw[i] = pw[i - 1] * 1ll * P % mod; } auto check = [&](int l, int r){ l--; return (h[r] - h[l] * 1ll * pw[r - l] % mod + mod) % mod == (h[n - l] - h[n - r] * 1ll * pw[r - l] % mod + mod) % mod; }; int res = 0, last = 1; for(int i=1;i<=n/2;i++){ if(check(last, i)){ //~ cout<<last<<" "<<i<<"\n"; res += 2; last = i + 1; } } if(n & 1) res++; else if(last <= n / 2) res++; cout<<res<<"\n"; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--){ 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...