# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
425176 | cpp219 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 143 ms | 28684 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.
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e6 + 9;
const ll mod = 1e9 + 7;
const ll base = 31;
typedef pair<ll,ll> LL;
string s;
ll T,n,Hash[N],fac[N];
ll GetHash(ll i,ll j){
return (Hash[j] - Hash[i - 1]*fac[j - i + 1] + mod*mod)%mod;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
fac[0] = 1;
for (ll i = 1;i < N;i++) fac[i] = (fac[i - 1]*base)%mod;
cin>>T;
while(T--){
cin>>s; n = s.size(); s = " " + s;
for (ll i = 1;i <= n;i++) Hash[i] = (Hash[i - 1]*base + s[i] - 'a' + 1)%mod;
ll ans = 0;
ll L = 1,R = n;
while(L <= R){
ll chosen = mod;
for (ll len = 1;len <= R - L + 1;len++){
ll p = GetHash(L,L + len - 1),q = GetHash(R - len + 1,R);
//cout<<len<<" "<<p<<" "<<q<<"\n";
if (p == q){
chosen = len; break;
}
}
ans++;
if (chosen != R - L + 1) ans++; //cout<<chosen; return 0;
L = L + chosen; R = R - chosen;
}
cout<<ans<<"\n";
}
}
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... |