Submission #624407

# Submission time Handle Problem Language Result Execution time Memory
624407 2022-08-08T08:13:37 Z Iwanttobreakfree Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
296 ms 26912 KB
#include <iostream>
#include <vector>
using namespace std;
const int MAX_N=1e6+7,t=70,mod=1e9+7;
vector<long long> pre_hash(MAX_N),pre(MAX_N);
int get_hash(int a,int sz){
    //cout<<a<<' '<<sz<<' '<<pre_hash[a]<<' '<<pre[sz]<<'\n';
    return (((pre_hash[a+sz]-pre_hash[a]*pre[sz])%mod)+mod)%mod;
}
bool ok(int i,int j,int mid){
    //cout<<i<<' '<<j<<' '<<mid<<' '<<get_hash(i,mid)<<' '<<get_hash(j,mid)<<'\n';
    return get_hash(i,mid)==get_hash(j,mid);
}
int main(){
    int test;
    string s;
    cin>>test;
    pre[0]=1;
    for(int i=0;i<MAX_N-1;i++)pre[i+1]=(pre[i]*t)%mod;
    while(test--){
        cin>>s;
        int n=s.size();
        for(int i=0;i<n;i++)pre_hash[i+1]=(pre_hash[i]*t+s[i]-'a'+1)%mod;
        int ans=0,last=-1;
        for(int i=0;i<n/2;i++){
            int sz=i-last;
            if(ok(last+1,n-1-last-sz,sz)){
                ans+=2;
                last=i;
            }
        }
        if(n&1||last!=n/2-1)ans++;
        cout<<ans<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15956 KB Output is correct
2 Correct 11 ms 15868 KB Output is correct
3 Correct 12 ms 15972 KB Output is correct
4 Correct 11 ms 15956 KB Output is correct
5 Correct 11 ms 15956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15956 KB Output is correct
2 Correct 11 ms 15868 KB Output is correct
3 Correct 12 ms 15972 KB Output is correct
4 Correct 11 ms 15956 KB Output is correct
5 Correct 11 ms 15956 KB Output is correct
6 Correct 11 ms 15876 KB Output is correct
7 Correct 11 ms 15888 KB Output is correct
8 Correct 11 ms 15956 KB Output is correct
9 Correct 11 ms 15956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15956 KB Output is correct
2 Correct 11 ms 15868 KB Output is correct
3 Correct 12 ms 15972 KB Output is correct
4 Correct 11 ms 15956 KB Output is correct
5 Correct 11 ms 15956 KB Output is correct
6 Correct 11 ms 15876 KB Output is correct
7 Correct 11 ms 15888 KB Output is correct
8 Correct 11 ms 15956 KB Output is correct
9 Correct 11 ms 15956 KB Output is correct
10 Correct 13 ms 16104 KB Output is correct
11 Correct 13 ms 16060 KB Output is correct
12 Correct 14 ms 16020 KB Output is correct
13 Correct 15 ms 16008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15956 KB Output is correct
2 Correct 11 ms 15868 KB Output is correct
3 Correct 12 ms 15972 KB Output is correct
4 Correct 11 ms 15956 KB Output is correct
5 Correct 11 ms 15956 KB Output is correct
6 Correct 11 ms 15876 KB Output is correct
7 Correct 11 ms 15888 KB Output is correct
8 Correct 11 ms 15956 KB Output is correct
9 Correct 11 ms 15956 KB Output is correct
10 Correct 13 ms 16104 KB Output is correct
11 Correct 13 ms 16060 KB Output is correct
12 Correct 14 ms 16020 KB Output is correct
13 Correct 15 ms 16008 KB Output is correct
14 Correct 296 ms 26912 KB Output is correct
15 Correct 239 ms 22292 KB Output is correct
16 Correct 276 ms 26296 KB Output is correct
17 Correct 162 ms 21784 KB Output is correct