Submission #119390

#TimeUsernameProblemLanguageResultExecution timeMemory
119390zubecPalindromic Partitions (CEOI17_palindromic)C++14
100 / 100
155 ms28960 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N = 1000100; const ll MOD = 1e9+9; string s; int n; ll hsh[N], st[N]; ll gethsh(int l, int r){ return (hsh[r]-hsh[l-1]+MOD)*st[n-r]%MOD; } void solve(){ st[0] = 1; cin >> s; n = s.size(); s = '#' + s; for (int i = 1; i <= n; i++){ st[i] = (st[i-1] * 43) % MOD; hsh[i] = (hsh[i-1] + st[i]*s[i])%MOD; } int i = 1; int j = n; int sz = 1; int ans = 0; while(1){ if (i+sz-1 >= j-sz+1){ ++ans; break; } if (gethsh(i, i+sz-1) == gethsh(j-sz+1, j)){ ans += 2; i += sz; j -= sz; sz = 1; if (i-1 == j) break; continue; } ++sz; } cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int tt; cin >> tt; while(tt--){ solve(); } } /** 1 deleted */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...