結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー ぷらぷら
提出日時 2023-02-03 21:37:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 827 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 198,628 KB
実行使用メモリ 28,064 KB
最終ジャッジ日時 2023-09-15 17:15:56
合計ジャッジ時間 5,075 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 35 ms
23,468 KB
testcase_04 AC 11 ms
13,248 KB
testcase_05 AC 9 ms
11,160 KB
testcase_06 AC 60 ms
27,660 KB
testcase_07 AC 55 ms
27,592 KB
testcase_08 AC 52 ms
25,520 KB
testcase_09 AC 100 ms
27,584 KB
testcase_10 AC 80 ms
27,672 KB
testcase_11 AC 50 ms
25,500 KB
testcase_12 AC 62 ms
27,600 KB
testcase_13 AC 60 ms
27,708 KB
testcase_14 AC 74 ms
27,932 KB
testcase_15 AC 84 ms
27,848 KB
testcase_16 AC 25 ms
19,380 KB
testcase_17 AC 37 ms
21,484 KB
testcase_18 AC 63 ms
27,664 KB
testcase_19 AC 83 ms
27,648 KB
testcase_20 AC 70 ms
27,896 KB
testcase_21 AC 62 ms
28,064 KB
testcase_22 AC 66 ms
27,828 KB
testcase_23 AC 71 ms
28,008 KB
testcase_24 AC 118 ms
27,660 KB
testcase_25 AC 82 ms
27,756 KB
testcase_26 AC 59 ms
27,684 KB
testcase_27 AC 78 ms
23,556 KB
testcase_28 AC 78 ms
27,684 KB
testcase_29 AC 59 ms
28,064 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 93 ms
25,876 KB
testcase_33 AC 67 ms
27,836 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 93 ms
25,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool f[5050][5050];

int dp[5050];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++) {
        f[i][i+1] = true;
        if(i && S[i-1] == S[i]) {
            f[i-1][i+1] = true;
        }
    }
    for(int l = 1; l <= S.size(); l++) {
        for(int i = 0; i+l <= S.size(); i++) {
            int j = i+l;
            if(i && j < S.size() && S[i-1] == S[j] && f[i][j]) {
                f[i-1][j+1] = true;
            }
        }
    }
    dp[0] = S.size();
    for(int i = 0; i < S.size(); i++) {
        for(int j = i; j < S.size(); j++) {
            if(f[i][j+1]) {
                dp[j+1] = max(dp[j+1],min(dp[i],j-i+1));
            }
        }
    }
    cout << dp[S.size()] << endl;
}
0