結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー roarisroaris
提出日時 2023-02-03 22:23:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 1,467 ms
コンパイル使用メモリ 169,196 KB
実行使用メモリ 28,096 KB
最終ジャッジ日時 2023-09-15 18:26:17
合計ジャッジ時間 3,424 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 15 ms
17,496 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 19 ms
27,664 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 26 ms
27,716 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 85 ms
21,824 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];
        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