답안 #132743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132743 2019-07-19T12:47:47 Z Bench0310 Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
653 ms 45300 KB
#include <bits/stdc++.h>

using namespace std;
const int N=1000000;
const long long p=29;
const long long mod=1000000007;

long long e[N];
int n;
string s;
int dp[N];

int solve(int l,int r)
{
    if(l>r) return 0;
    if(l==r) return 1;
    if(dp[l]!=-1) return dp[l];
    int res=0;
    long long one=0,two=0;
    for(int i=0;l+i<r-i;i++)
    {
        one=((one*p)+(s[l+i]-'a'))%mod;
        two=(two+e[i]*(s[r-i]-'a'))%mod;
        if(one==two)
        {
            res=2+solve(l+i+1,r-i-1);
            break;
        }
    }
    if(res==0) res=1;
    return dp[l]=res;
}

int main()
{
    e[0]=1;
    for(int i=1;i<N;i++) e[i]=(e[i-1]*p)%mod;
    int t;
    cin >> t;
    while(t--)
    {
        cin >> s;
        n=s.size();
        memset(dp,-1,sizeof dp);
        cout << solve(0,n-1) << endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 12028 KB Output is correct
2 Correct 21 ms 12024 KB Output is correct
3 Correct 19 ms 12152 KB Output is correct
4 Correct 19 ms 12024 KB Output is correct
5 Correct 19 ms 12024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 12028 KB Output is correct
2 Correct 21 ms 12024 KB Output is correct
3 Correct 19 ms 12152 KB Output is correct
4 Correct 19 ms 12024 KB Output is correct
5 Correct 19 ms 12024 KB Output is correct
6 Correct 19 ms 12024 KB Output is correct
7 Correct 18 ms 12024 KB Output is correct
8 Correct 19 ms 11996 KB Output is correct
9 Correct 19 ms 12024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 12028 KB Output is correct
2 Correct 21 ms 12024 KB Output is correct
3 Correct 19 ms 12152 KB Output is correct
4 Correct 19 ms 12024 KB Output is correct
5 Correct 19 ms 12024 KB Output is correct
6 Correct 19 ms 12024 KB Output is correct
7 Correct 18 ms 12024 KB Output is correct
8 Correct 19 ms 11996 KB Output is correct
9 Correct 19 ms 12024 KB Output is correct
10 Correct 25 ms 12280 KB Output is correct
11 Correct 21 ms 12152 KB Output is correct
12 Correct 25 ms 12152 KB Output is correct
13 Correct 24 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 12028 KB Output is correct
2 Correct 21 ms 12024 KB Output is correct
3 Correct 19 ms 12152 KB Output is correct
4 Correct 19 ms 12024 KB Output is correct
5 Correct 19 ms 12024 KB Output is correct
6 Correct 19 ms 12024 KB Output is correct
7 Correct 18 ms 12024 KB Output is correct
8 Correct 19 ms 11996 KB Output is correct
9 Correct 19 ms 12024 KB Output is correct
10 Correct 25 ms 12280 KB Output is correct
11 Correct 21 ms 12152 KB Output is correct
12 Correct 25 ms 12152 KB Output is correct
13 Correct 24 ms 12152 KB Output is correct
14 Correct 653 ms 45300 KB Output is correct
15 Correct 350 ms 33244 KB Output is correct
16 Correct 588 ms 22508 KB Output is correct
17 Correct 344 ms 23976 KB Output is correct