답안 #520285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520285 2022-01-29T07:24:58 Z krit3379 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
244 ms 28620 KB
#include<bits/stdc++.h>
using namespace std;
#define N 1000005

long long hx[N],bp[N],p=31,mod=1e9+7;

long long val(int i,int j){
    return ((hx[j]-hx[i-1]*bp[j-i+1])%mod+mod)%mod;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int t,n,i,j,ans;
    string s;
    cin>>t;
    bp[0]=1;
    for(i=1;i<N;i++)bp[i]=(bp[i-1]*p)%mod;
    while(t--){
        cin>>s;
        ans=0;
        n=s.length();
        s='0'+s;
        for(i=1;i<=n;i++)hx[i]=0;
        for(i=1;i<=n;i++)hx[i]=(hx[i-1]*p+s[i]-'a'+1)%mod;
        for(i=1,j=1;j<=n/2;j++){
            if(val(i,j)==val(n-j+1,n-i+1)){
                ans+=2;
                i=j+1;
            }
        }
        if(n%2||i!=j)ans++;
        cout<<ans<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8004 KB Output is correct
2 Correct 9 ms 8044 KB Output is correct
3 Correct 9 ms 8120 KB Output is correct
4 Correct 9 ms 8144 KB Output is correct
5 Correct 9 ms 8128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8004 KB Output is correct
2 Correct 9 ms 8044 KB Output is correct
3 Correct 9 ms 8120 KB Output is correct
4 Correct 9 ms 8144 KB Output is correct
5 Correct 9 ms 8128 KB Output is correct
6 Correct 8 ms 8076 KB Output is correct
7 Correct 9 ms 8148 KB Output is correct
8 Correct 9 ms 8140 KB Output is correct
9 Correct 9 ms 8128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8004 KB Output is correct
2 Correct 9 ms 8044 KB Output is correct
3 Correct 9 ms 8120 KB Output is correct
4 Correct 9 ms 8144 KB Output is correct
5 Correct 9 ms 8128 KB Output is correct
6 Correct 8 ms 8076 KB Output is correct
7 Correct 9 ms 8148 KB Output is correct
8 Correct 9 ms 8140 KB Output is correct
9 Correct 9 ms 8128 KB Output is correct
10 Correct 10 ms 8268 KB Output is correct
11 Correct 10 ms 8268 KB Output is correct
12 Correct 13 ms 8268 KB Output is correct
13 Correct 11 ms 8220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8004 KB Output is correct
2 Correct 9 ms 8044 KB Output is correct
3 Correct 9 ms 8120 KB Output is correct
4 Correct 9 ms 8144 KB Output is correct
5 Correct 9 ms 8128 KB Output is correct
6 Correct 8 ms 8076 KB Output is correct
7 Correct 9 ms 8148 KB Output is correct
8 Correct 9 ms 8140 KB Output is correct
9 Correct 9 ms 8128 KB Output is correct
10 Correct 10 ms 8268 KB Output is correct
11 Correct 10 ms 8268 KB Output is correct
12 Correct 13 ms 8268 KB Output is correct
13 Correct 11 ms 8220 KB Output is correct
14 Correct 231 ms 27572 KB Output is correct
15 Correct 132 ms 22832 KB Output is correct
16 Correct 244 ms 28620 KB Output is correct
17 Correct 118 ms 18364 KB Output is correct