結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー tsugutsugutsugutsugu
提出日時 2023-03-05 13:56:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 174,348 KB
実行使用メモリ 6,804 KB
最終ジャッジ日時 2023-10-18 04:53:22
合計ジャッジ時間 5,014 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 25 ms
5,356 KB
testcase_04 AC 7 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 43 ms
6,804 KB
testcase_07 AC 37 ms
6,412 KB
testcase_08 AC 33 ms
5,884 KB
testcase_09 AC 34 ms
6,148 KB
testcase_10 AC 41 ms
6,804 KB
testcase_11 AC 33 ms
5,884 KB
testcase_12 AC 43 ms
6,788 KB
testcase_13 AC 43 ms
6,804 KB
testcase_14 AC 41 ms
6,804 KB
testcase_15 AC 38 ms
6,516 KB
testcase_16 AC 16 ms
4,564 KB
testcase_17 AC 21 ms
5,092 KB
testcase_18 AC 45 ms
6,804 KB
testcase_19 AC 42 ms
6,804 KB
testcase_20 AC 43 ms
6,804 KB
testcase_21 AC 42 ms
6,804 KB
testcase_22 AC 43 ms
6,804 KB
testcase_23 AC 42 ms
6,804 KB
testcase_24 AC 43 ms
6,804 KB
testcase_25 AC 43 ms
6,804 KB
testcase_26 AC 43 ms
6,804 KB
testcase_27 AC 41 ms
5,356 KB
testcase_28 AC 42 ms
6,804 KB
testcase_29 AC 41 ms
6,804 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 55 ms
5,884 KB
testcase_33 AC 41 ms
6,804 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 55 ms
5,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<bool>> p(n, vector<bool>(n + 1, false));
    for (int i = 0; i < n; i++) {
        p[i][i + 1] = true;
        if (i < n - 1) {
            p[i][i + 2] = (s[i] == s[i + 1]);
        }
    }
    for (int len = 3; len <= n; len++) {
        for (int i = 0; i + len <= n; i++) {
            if (p[i + 1][i + len - 1] && s[i] == s[i + len - 1]) {
                p[i][i + len] = true;
            }
        }
    }
    vector<int> dp(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            if (p[j][i]) {
                if (j == 0) {
                    dp[i] = max(dp[i], i);
                } else {
                    dp[i] = max(dp[i], min(dp[j], i - j));
                }
            }
        }
    }
    cout << dp[n] << '\n';
}
0