結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー srjywrdnprkt
提出日時 2023-01-25 15:54:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 976 ms
コンパイル使用メモリ 111,696 KB
最終ジャッジ日時 2025-02-10 06:45:29
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 29 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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