結果

問題 No.273 回文分解
ユーザー nasadigital
提出日時 2015-08-29 02:11:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 565 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 157,792 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 13:26:50
合計ジャッジ時間 2,335 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

string s;
int dp[51];

bool chk(int st,int ed){
    ed--;
    while(st<ed){
        if(s[st]!=s[ed])
            return false;
        st++;
        ed--;
    }
    return true;
}

int rek(int st,bool a){
    if(dp[st]==-1){
    int r=1;
    for(int ctr1=st+1;ctr1<=s.length()-a;ctr1++){
        if(chk(st,ctr1)){
            r=max(ctr1-st,max(r,rek(ctr1,false)));
        }
    }
    dp[st]=r;
    }
    return dp[st];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>s;
    cout<<rek(0,true);
    return 0;
}
0