結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-12-03 02:21:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,433 bytes
コンパイル時間 2,658 ms
コンパイル使用メモリ 208,172 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-03 02:21:22
合計ジャッジ時間 6,866 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 59 ms
6,676 KB
testcase_04 AC 15 ms
6,676 KB
testcase_05 AC 9 ms
6,676 KB
testcase_06 AC 103 ms
6,676 KB
testcase_07 AC 90 ms
6,676 KB
testcase_08 AC 84 ms
6,676 KB
testcase_09 AC 88 ms
6,676 KB
testcase_10 AC 102 ms
6,676 KB
testcase_11 AC 83 ms
6,676 KB
testcase_12 AC 99 ms
6,676 KB
testcase_13 AC 102 ms
6,676 KB
testcase_14 AC 100 ms
6,676 KB
testcase_15 AC 93 ms
6,676 KB
testcase_16 AC 40 ms
6,676 KB
testcase_17 AC 50 ms
6,676 KB
testcase_18 AC 99 ms
6,676 KB
testcase_19 AC 101 ms
6,676 KB
testcase_20 AC 103 ms
6,676 KB
testcase_21 AC 102 ms
6,676 KB
testcase_22 AC 103 ms
6,676 KB
testcase_23 AC 103 ms
6,676 KB
testcase_24 AC 100 ms
6,676 KB
testcase_25 AC 99 ms
6,676 KB
testcase_26 AC 98 ms
6,676 KB
testcase_27 AC 66 ms
6,676 KB
testcase_28 AC 100 ms
6,676 KB
testcase_29 AC 100 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 84 ms
6,676 KB
testcase_33 AC 103 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 87 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD1=1e9+7, BASE1=272783711;
const ll MOD2=999999937, BASE2=483283287;

template<typename T, T MOD, T BASE>
struct RollingHash{
    int N;
    vector<ll> hash, bpow;
    RollingHash(const vector<T> &v) {init(v);}
    void init(vector<T> &v){
        N = v.size();
        hash.resize(N+1); bpow.resize(N+1);
        bpow[0] = 1;
        for (int i=0; i<N; i++){
            hash[i+1] = (hash[i] * BASE + v[i]) % MOD;
            bpow[i+1] = (bpow[i] * BASE) % MOD;
        }
    }
    RollingHash(const string &s){
        vector<T> v(s.begin(), s.end());
        init(v);
    }
    //0-indexed (Hash of S[l:r])
    ll get(ll l, ll r){
        r++;
        return (hash[r]+MOD-(hash[l]*bpow[r-l])%MOD) % MOD;
    }
};

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int N;
    string S, T;
    cin >> S;
    T = S;
    N = S.size();
    reverse(T.begin(), T.end());
    RollingHash<ll, MOD1, BASE1> rh1(S), rh2(T);
    //Is S[l:r] palindrome?
    auto f=[&](int l, int r)->bool{
        int len=r-l+1;
        return rh1.get(l, l+len/2-1) == rh2.get(N-1-r, N-1-(r-len/2+1));
    };

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

    cout << dp[N] << endl;

    return 0;
}
0