Submission #1092812

# Submission time Handle Problem Language Result Execution time Memory
1092812 2024-09-25T07:44:09 Z owoovo Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
1 ms 856 KB
#include<bits/stdc++.h>
#define ll long long
#define F first 
#define S second 
using namespace std;
const ll p=1e9+7;
const ll c=31;
ll hah[1000010];
ll inv(ll a){
    return (p-p/a)*int(p%a)%p;
}
ll pw(ll a,ll b){
    ll ans=1;

    while(b){
        if(b&1)ans*=a,ans%=p;
        b>>=1;
        a*=a;
        a%=p;
    }
    return ans;
}
ll hh(int l,int r){
    return ((hah[r]-hah[l-1]*pw(c,r-l+1))%p+p)%p;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n=s.size();
        for(int i=1;i<=n;i++){
            char ch=s[i-1];
            ll val=int(ch-'a')+1;
            hah[i]=hah[i-1]*c+val;
            hah[i]%=p;
        }
        int l=1,r=n,i=0,ans=0;
        while(l<=r){
            while(l+i!=r&&hh(l,l+i)!=hh(r-i,r)){
                i++;
            }
            ans+=2;
            l=l+i+1,r=r-i-1;
        }
        cout<<ans-1<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -