結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー HIcoderHIcoder
提出日時 2023-07-14 23:33:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 2,002 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 107,372 KB
実行使用メモリ 6,748 KB
最終ジャッジ日時 2023-10-14 14:03:18
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 12 ms
5,200 KB
testcase_04 AC 5 ms
4,352 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 20 ms
6,488 KB
testcase_07 AC 18 ms
6,276 KB
testcase_08 AC 16 ms
5,940 KB
testcase_09 AC 17 ms
6,056 KB
testcase_10 AC 19 ms
6,500 KB
testcase_11 AC 16 ms
6,008 KB
testcase_12 AC 20 ms
6,492 KB
testcase_13 AC 19 ms
6,564 KB
testcase_14 AC 20 ms
6,544 KB
testcase_15 AC 19 ms
6,236 KB
testcase_16 AC 9 ms
4,864 KB
testcase_17 AC 11 ms
5,008 KB
testcase_18 AC 19 ms
6,748 KB
testcase_19 AC 19 ms
6,536 KB
testcase_20 AC 19 ms
6,604 KB
testcase_21 AC 19 ms
6,556 KB
testcase_22 AC 20 ms
6,508 KB
testcase_23 AC 19 ms
6,504 KB
testcase_24 AC 19 ms
6,612 KB
testcase_25 AC 19 ms
6,736 KB
testcase_26 AC 19 ms
6,476 KB
testcase_27 AC 14 ms
5,496 KB
testcase_28 AC 19 ms
6,500 KB
testcase_29 AC 20 ms
6,476 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 47 ms
5,712 KB
testcase_33 AC 19 ms
6,596 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 48 ms
5,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);


int main(){
    string S;
    cin>>S;
    int N=S.size();

    vector<vector<bool>> ok(N,vector<bool>(N,false));

    for(int i=0;i<N;i++){
        //[i,i]は1文字で当然回文
        int l=i,r=i;
        while(l>=0 && r<N && S[l]==S[r]){
            ok[l][r]=true;
            l--;r++;
        }
        
    }

    for(int i=0;i<N;i++){
        //[i,i+1]は2文字で回文のときある
        int l=i,r=i+1;
        while(l>=0 && r<N && S[l]==S[r]){
            ok[l][r]=true;
            l--;r++;
        }
    }

    /*
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            if(ok[i][j]){
                cout<<"i="<<i<<",j="<<j<<endl;
            }

            //cout<<"ok["<<i<<"]["<<j<<"]="<<ok[i][j];
        }
        cout<<endl;
    }
    */
    
    vector<int> dp(N+1,0);
    dp[0]=N; 

    /*
    for(int i=0;i<N;i++){
        for(int j=0;j<i;j++){
            //dp[i]=
            //[j+1,i]が回文のとき
            if(j+1<=i && j+1<=N-1 && ok[j+1][i]){
                dp[i]=max(dp[i],min(dp[j],i-j));
            }
        }
    }
    */
   
    for(int i=0;i<N;i++){
        for(int j=i+1;j<=N;j++){
            
            //[i,j]が回文のとき
            if(ok[i][j-1]){
                int len=j-i;
                dp[j]=max(dp[j],min(dp[i],len));
            }
        }
    }
    

    
    int ans=0;
    /*
    for(int i=0;i<N;i++){
        cout<<"dp["<<i<<"]="<<dp[i]<<endl;
        ans=max(ans,dp[i]);
    }
    */
   /*
    for(int i=0;i<N;i++){
        if(i+1<=N-1 && ok[i+1][N-1]){
            ans=max(ans,min(dp[i], N-1-i ));
        }
    }

    cout<<ans<<endl;
    */
    
    cout<<dp[N]<<endl;







}
0