답안 #141315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141315 2019-08-07T12:13:08 Z rzbt Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
165 ms 26712 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 1000006
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

char s[MAXN];
ll n;
ll p[MAXN];
ll hes[MAXN];
void hesuj(){
    p[0]=1;
    hes[1]=s[0]-'a';
    for(int i=1;i<n;i++){
        p[i]=(p[i-1]*37)%MOD;
        hes[i+1]=(hes[i]+p[i]*(s[i]-'a'))%MOD;
    }
}

int main()
{
    int ttt;
    scanf("%d",&ttt);
    while(ttt--){
        scanf("%s",s);
        n=strlen(s);
        int l=0,d=n-1,pl=0,pd=n-1,res=0;

        hesuj();
        while(l<=d){
            if(pl==pd)break;
            if(((MOD+hes[l+1]-hes[pl])*p[d])%MOD==((MOD-hes[d]+hes[pd+1])*p[pl])%MOD){
                res+=2;
                pl=l+1;
                pd=d-1;
            }

            l++;
            d--;
        }
        if(pl>pd)printf("%d\n",res);
        else{
            printf("%d\n",res+1);

        }

    }

    return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&ttt);
     ~~~~~^~~~~~~~~~~
palindromic.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",s);
         ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 360 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 360 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
13 Correct 4 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 360 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
13 Correct 4 ms 508 KB Output is correct
14 Correct 165 ms 26712 KB Output is correct
15 Correct 86 ms 22136 KB Output is correct
16 Correct 145 ms 26240 KB Output is correct
17 Correct 91 ms 14200 KB Output is correct