結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー 👑 NachiaNachia
提出日時 2023-02-03 21:32:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,758 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 81,908 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 16:59:16
合計ジャッジ時間 2,288 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#line 1 "nachia\\string\\enumerate-palindromes.hpp"

#line 4 "nachia\\string\\enumerate-palindromes.hpp"


namespace nachia{

std::vector<int> EnumeratePalindromes(const std::string& S) {
    int n = S.size();
    if (n == 0) return { 0 };
    std::string sx(n * 2 + 1, '$');
    for (int i = 0; i < n; i++) sx[i * 2 + 1] = S[i];
    n = n * 2 + 1;
    std::vector<int> res(n);
    int r = 0;
    for (int i = 0; i < n; ) {
        while ((0 <= i - r && i + r < n) ? (sx[i - r] == sx[i + r]) : false) r++;
        res[i] = r;
        int di = 1;
        while ((0 <= i - di && i + di < n) ? (res[i - di] < r - di) : false) {
            res[i + di] = res[i - di];
            di++;
        }
        r -= di;
        i += di;
    }
    for (int i = 0; i + 1 < n; i++) res[i] = res[i + 1] - 1;
    res.resize(n - 2);
    return res;
}

} // namespace nachia
#line 7 "Main.cpp"
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

int main(){
    string S; cin >> S;
    auto P = nachia::EnumeratePalindromes(S);
    int N = S.size();
    vector<int> dp(N+1, -1);
    dp[0] = 1000000;
    rep(i,P.size()){
        for(int c=1-i%2; c<=P[i]; c+=2){
            int s = (i-c+1)/2;
            dp[s+c] = max(dp[s+c], min(dp[s], c));
        }
    }
    cout << dp[N] << endl;
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0