結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー roarisroaris
提出日時 2023-02-03 22:24:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 201,088 KB
実行使用メモリ 27,824 KB
最終ジャッジ日時 2023-09-15 18:27:12
合計ジャッジ時間 3,861 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 15 ms
17,752 KB
testcase_04 AC 5 ms
6,596 KB
testcase_05 AC 4 ms
5,272 KB
testcase_06 AC 19 ms
27,672 KB
testcase_07 AC 17 ms
25,208 KB
testcase_08 AC 16 ms
23,248 KB
testcase_09 AC 18 ms
24,072 KB
testcase_10 AC 20 ms
27,672 KB
testcase_11 AC 17 ms
23,104 KB
testcase_12 AC 21 ms
27,492 KB
testcase_13 AC 19 ms
27,628 KB
testcase_14 AC 19 ms
27,644 KB
testcase_15 AC 19 ms
25,700 KB
testcase_16 AC 9 ms
12,672 KB
testcase_17 AC 11 ms
15,628 KB
testcase_18 AC 20 ms
27,672 KB
testcase_19 AC 20 ms
27,592 KB
testcase_20 AC 20 ms
27,576 KB
testcase_21 AC 19 ms
27,784 KB
testcase_22 AC 19 ms
27,712 KB
testcase_23 AC 19 ms
27,780 KB
testcase_24 AC 20 ms
27,680 KB
testcase_25 AC 22 ms
27,760 KB
testcase_26 AC 26 ms
27,788 KB
testcase_27 AC 26 ms
19,228 KB
testcase_28 AC 19 ms
27,824 KB
testcase_29 AC 18 ms
27,648 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 15 ms
21,664 KB
testcase_33 AC 18 ms
27,544 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 68 ms
21,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef long long ll;

vector<int> manacher(string s) {
    int n = s.size();
    vector<int> res(n);
    int i = 0;
    int j = 0;
    while (i<n) {
        while (i-j>=0 && i+j<n && s[i-j]==s[i+j]) j++;
        res[i] = j;
        int k = 1;
        while (i-k>=0 && k+res[i-k]<j) {
            res[i+k] = res[i-k];
            k += 1;
        }
        i += k;
        j -= k;
    }
    return res;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    string S; cin >> S;
    string T;
    for (char c : S) {
        T += '&';
        T += c;
    }
    vector<int> mana = manacher(T);
    int n = S.size();
    bool is_pal[n][n+1];
    rep(l, n) for (int r=l+1; r<=n; r++) {
        int center = l+r;
        is_pal[l][r] = 2*r-1<center+mana[center];
    }
    
    int ok = 1;
    int ng = n+10;
    while (abs(ok-ng)>1) {
        int mid = (ok+ng)/2;
        bool dp[n+1];
        fill(dp, dp+n+1, false);
        dp[0] = true;
        rep(i, n) {
            if (!dp[i]) continue;
            for (int j=i+mid; j<=n; j++) if (is_pal[i][j]) dp[j] = true;
        }
        if (dp[n]) ok = mid;
        else ng = mid;
    }
    
    cout << ok << endl;
}
0