結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー Manuel1024Manuel1024
提出日時 2023-08-24 02:38:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 77,112 KB
実行使用メモリ 6,732 KB
最終ジャッジ日時 2023-08-24 02:38:10
合計ジャッジ時間 3,614 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 15 ms
5,196 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 24 ms
6,584 KB
testcase_07 AC 21 ms
6,264 KB
testcase_08 AC 20 ms
5,916 KB
testcase_09 AC 20 ms
6,112 KB
testcase_10 AC 24 ms
6,712 KB
testcase_11 AC 19 ms
5,892 KB
testcase_12 AC 24 ms
6,452 KB
testcase_13 AC 24 ms
6,624 KB
testcase_14 AC 24 ms
6,464 KB
testcase_15 AC 23 ms
6,456 KB
testcase_16 AC 10 ms
4,732 KB
testcase_17 AC 12 ms
5,032 KB
testcase_18 AC 24 ms
6,472 KB
testcase_19 AC 25 ms
6,520 KB
testcase_20 AC 24 ms
6,512 KB
testcase_21 AC 24 ms
6,716 KB
testcase_22 AC 25 ms
6,508 KB
testcase_23 AC 24 ms
6,732 KB
testcase_24 AC 24 ms
6,476 KB
testcase_25 AC 25 ms
6,556 KB
testcase_26 AC 24 ms
6,476 KB
testcase_27 AC 27 ms
5,412 KB
testcase_28 AC 24 ms
6,516 KB
testcase_29 AC 24 ms
6,488 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 49 ms
5,868 KB
testcase_33 AC 24 ms
6,624 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 48 ms
5,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s; cin >> s;
    const int n = s.size();
    vector<vector<bool>> ispalindrome(n+1, vector<bool>(n+1, false));
    for(int i = 0; i < n; i++){
        for(int j = 0; 0 <= i-j && i+j < n; j++){
            if(s[i-j] != s[i+j]) break;
            ispalindrome[i-j][i+j+1] = true;
        }
        if(i+1 < n && s[i] == s[i+1]){
            for(int j = 0; 0 <= i-j && i+j+1 < n; j++){
                if(s[i-j] != s[i+j+1]) break;
                ispalindrome[i-j][i+j+2] = true;
            }
        }
    }

    vector<int> dp(n+1, -(1 << 30));
    dp[0] = 1 << 30;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= i; j++){
            if(ispalindrome[j][i+1]){
                dp[i+1] = max(dp[i+1], min(dp[j], i+1-j));
            }
        }
        // cerr << dp[i+1] << " ";
    }
    cout << dp[n] << endl;
    return 0;
}
0