結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-24 20:47:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 3,007 ms
コンパイル使用メモリ 113,996 KB
実行使用メモリ 6,724 KB
最終ジャッジ日時 2023-08-27 02:35:04
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 37 ms
5,392 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 65 ms
6,536 KB
testcase_07 AC 58 ms
6,224 KB
testcase_08 AC 55 ms
5,908 KB
testcase_09 AC 86 ms
6,004 KB
testcase_10 AC 78 ms
6,724 KB
testcase_11 AC 51 ms
6,108 KB
testcase_12 AC 66 ms
6,520 KB
testcase_13 AC 65 ms
6,404 KB
testcase_14 AC 77 ms
6,424 KB
testcase_15 AC 79 ms
6,252 KB
testcase_16 AC 25 ms
4,724 KB
testcase_17 AC 36 ms
4,992 KB
testcase_18 AC 67 ms
6,428 KB
testcase_19 AC 82 ms
6,500 KB
testcase_20 AC 73 ms
6,516 KB
testcase_21 AC 64 ms
6,532 KB
testcase_22 AC 68 ms
6,472 KB
testcase_23 AC 73 ms
6,600 KB
testcase_24 AC 102 ms
6,424 KB
testcase_25 AC 82 ms
6,592 KB
testcase_26 AC 65 ms
6,444 KB
testcase_27 AC 75 ms
5,484 KB
testcase_28 AC 81 ms
6,444 KB
testcase_29 AC 65 ms
6,704 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 65 ms
5,664 KB
testcase_33 AC 69 ms
6,592 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 68 ms
5,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    string S;
    cin >> S;
    assert(S.size() <= 5000);
    for (auto x : S) assert('a' <= x && x <= 'z');

    int N = S.size();
    vector<vector<bool>> ok(N+1, vector<bool>(N+1));

    for (int i=N; i>=1; i--){
        for (int j=i; j<=N; j++){
            ok[i][j] = (S[i-1] == S[j-1]);
            if (i+1 <= j-1) ok[i][j] = (ok[i][j] & ok[i+1][j-1]);
        }
    }

    vector<int> dp(N+1);
    dp[0] = 1e9;

    for (int i=1; i<=N; i++){
        for (int j=0; j<i; j++){
            if (ok[j+1][i]) dp[i] = max(dp[i], min(dp[j], i-j));
        }
    }

    cout << dp[N] << endl;

    return 0;
}
0