Submission #397378

# Submission time Handle Problem Language Result Execution time Memory
397378 2021-05-02T01:51:28 Z Pichon5 Palindromic Partitions (CEOI17_palindromic) C++17
35 / 100
8 ms 1228 KB
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int dp[301][301];
string s;
int f(int b, int e){
    if(e<b)return 0;
    if(b==e)return 1;
    if(dp[b][e]!=-1)return dp[b][e];
    dp[b][e]=1;
    for(int i=1;i<=e-b+1;i++){
        if(i+i>e-b+1)break;
        string A=s.substr(b,i);
        string B=s.substr(e-i+1,i);
        if(A==B){
            dp[b][e]=max(dp[b][e],2+f(b+i,e-i));
        }
    }
    return dp[b][e];
}
void init(){
    for(int i=0;i<=300;i++){
        for(int l=0;l<=300;l++)dp[i][l]=-1;
    }
}
int main()
{
    int n,t;
    cin>>t;
    while(t--){
        cin>>s;
        init();
        int n=s.size();
        cout<<f(0,n-1)<<endl;
    }
    return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:29:9: warning: unused variable 'n' [-Wunused-variable]
   29 |     int n,t;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 8 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 8 ms 588 KB Output is correct
10 Runtime error 2 ms 1228 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 8 ms 588 KB Output is correct
10 Runtime error 2 ms 1228 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -