# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703679 | mychecksedad | Palindromic Partitions (CEOI17_palindromic) | C++17 | 231 ms | 34556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;
int n;
string s;
ll h[N], p[N], rp[N];
ll po(ll a, ll b){ll res = 1; while(b){if(b&1) (res*=a)%=MOD; b>>=1; (a*=a)%=MOD;} return res;}
ll mod(ll x){
x %= MOD;
x = (x+MOD)%MOD;
return x;
}
void solve(){
cin >> s;
n = s.length();
h[0] = 0;
for(int i = 1; i <= n; ++i){
h[i] = (h[i - 1] + p[i] * (s[i - 1] - 'a' + 1)) % MOD;
}
int ans = 1, last = 1;
for(int i = 1; i <= n/2; ++i){
if(mod((h[n - last + 1] - h[n - i]) * rp[n - i]) == mod((h[i] - h[last - 1]) * rp[last - 1])){
ans += 2;
last = i + 1;
}
}
if(n % 2 == 0 && last == n/2 + 1) ans--;
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
cin >> T;aa=T;
p[0] = 1;
for(int i = 1; i < N; ++i) p[i] = (p[i - 1] * 37) % MOD;
for(int i = 0; i < N; ++i) rp[i] = po(p[i], MOD-2);
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |