結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー i_am_noob
提出日時 2023-02-12 03:05:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 191,140 KB
最終ジャッジ日時 2025-02-10 14:39:08
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

const int maxn=5005;
int n,dp[maxn];
string s;
bool a[maxn][maxn];

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> s; n=s.size();
    for(int i=0; i<=2*n-2; ++i){
        int l=i/2,r=i-l;
        while(l>=0&&r<n&&s[l]==s[r]) a[r][l]=1,l--,r++;
    }
    dp[0]=n+1;
    for(int i=0; i<n; ++i){
        dp[i+1]=-1;
        for(int j=0; j<=i; ++j) if(a[i][j]) dp[i+1]=max(dp[i+1],min(dp[j],i-j+1));
    }
    cout << dp[n] << "\n";
}
0