結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-25 15:54:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 1,325 ms
コンパイル使用メモリ 114,648 KB
実行使用メモリ 6,796 KB
最終ジャッジ日時 2023-09-09 09:25:44
合計ジャッジ時間 5,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 6 ms
4,384 KB
testcase_06 AC 62 ms
6,468 KB
testcase_07 AC 57 ms
6,196 KB
testcase_08 AC 53 ms
6,184 KB
testcase_09 AC 86 ms
6,220 KB
testcase_10 AC 76 ms
6,792 KB
testcase_11 AC 51 ms
6,164 KB
testcase_12 AC 64 ms
6,568 KB
testcase_13 AC 62 ms
6,516 KB
testcase_14 AC 73 ms
6,520 KB
testcase_15 AC 78 ms
6,240 KB
testcase_16 AC 24 ms
4,748 KB
testcase_17 AC 36 ms
4,952 KB
testcase_18 AC 64 ms
6,796 KB
testcase_19 AC 79 ms
6,488 KB
testcase_20 AC 71 ms
6,516 KB
testcase_21 AC 62 ms
6,460 KB
testcase_22 AC 65 ms
6,448 KB
testcase_23 AC 71 ms
6,488 KB
testcase_24 AC 101 ms
6,464 KB
testcase_25 AC 80 ms
6,576 KB
testcase_26 AC 61 ms
6,648 KB
testcase_27 WA -
testcase_28 AC 76 ms
6,448 KB
testcase_29 AC 61 ms
6,540 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 68 ms
6,548 KB
testcase_34 WA -
testcase_35 AC 44 ms
5,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <cassert>

using namespace std;

int N;
string S;
vector<vector<bool>> ok;

bool solve(int x){
    int prev = 0;
    for (int i=1; i<=N; i++){
        if (ok[prev+1][i] && i-prev>=x) prev = i;
    }
    return (N == prev); 
}

int main(){

    int l, r, c;
    cin >> S;
    assert(S.size() <= 5000);
    for (auto x : S) assert('a' <= x && x <= 'z');

    N = S.size();
    ok.resize(N+1, vector<bool>(N+1));

    for (int i=N; i>=1; i--){
        for (int j=i; j<=N; j++){
            ok[i][j] = (S[i-1] == S[j-1]);
            if (i+1 <= j-1) ok[i][j] = (ok[i][j] & ok[i+1][j-1]);
        }   
    }   

    l = 1, r = N+1;
    while(r-l > 1){ 
        c = (r+l) / 2LL;
        if (solve(c)) l = c;
        else r = c;
    }

    cout << l << endl;

    return 0;
}
0