結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-27 02:34:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 3,513 ms
コンパイル使用メモリ 200,860 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 02:34:48
合計ジャッジ時間 6,114 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 27 ms
4,384 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 44 ms
4,380 KB
testcase_07 AC 40 ms
4,380 KB
testcase_08 AC 36 ms
4,380 KB
testcase_09 AC 38 ms
4,380 KB
testcase_10 AC 44 ms
4,380 KB
testcase_11 AC 36 ms
4,380 KB
testcase_12 AC 43 ms
4,380 KB
testcase_13 AC 45 ms
4,380 KB
testcase_14 AC 44 ms
4,380 KB
testcase_15 AC 41 ms
4,376 KB
testcase_16 AC 18 ms
4,380 KB
testcase_17 AC 23 ms
4,380 KB
testcase_18 AC 44 ms
4,380 KB
testcase_19 AC 44 ms
4,380 KB
testcase_20 AC 44 ms
4,380 KB
testcase_21 AC 44 ms
4,376 KB
testcase_22 AC 44 ms
4,376 KB
testcase_23 AC 44 ms
4,376 KB
testcase_24 AC 44 ms
4,380 KB
testcase_25 AC 45 ms
4,380 KB
testcase_26 AC 44 ms
4,380 KB
testcase_27 AC 29 ms
4,380 KB
testcase_28 AC 44 ms
4,380 KB
testcase_29 AC 44 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 43 ms
4,376 KB
testcase_33 AC 44 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 44 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//R[2n]...n文字目を中心とする最長回文長
//R[2n+1]...n文字目とn+1文字目を中心とする最長回文長
template <typename T>
vector<int> manacher(T &s){
    string S="";
    for (auto x : s){
        S += x;
        S += '$';
    }
    S.pop_back();
    vector<int> R(S.size());
    int i=0, j=0;
    while(i < S.size()){
        while(i-j >= 0 && i+j < S.size() && S[i-j] == S[i+j]) j++;
        R[i] = j;
        int k=1;
        while(i-k >= 0 && k + R[i-k] < j){
            R[i+k] = R[i-k];
            k++;
        }
        i += k;
        j -= k;
    }

    for (int i=0; i<S.size(); i++){
        if (i % 2 == R[i] % 2) R[i]--;
    }

    return R;
}

int main(){

    string S;
    cin >> S;
    int N = S.size();
    vector<int> dp(N+1), R = manacher(S);
    dp[0] = 1e9;
    for (int i=1; i<=N; i++){
        for (int j=1; j<=N; j++){
            if (R[i+j-2] >= i-j+1){
                dp[i] = max(dp[i], min(dp[j-1], i-j+1));
            }
        }
    }

    cout << dp[N] << endl;

    return 0;
}
0