結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー FplusFplusF
提出日時 2023-07-31 22:23:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,335 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 203,272 KB
最終ジャッジ日時 2025-02-15 21:11:51
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    ll n=s.size();
    vector<vector<bool>> dp(n,vector<bool>(n,false));
    rep(i,n) dp[i][i]=true;
    for(ll i=n-1;0<=i;i--){
        for(ll j=i;j<n;j++){
            if(i==j) dp[i][j]=true;
            else if(i+1==j){
                if(s[i]==s[j]) dp[i][j]=true;
            }else{
                if(s[i]==s[j]&&dp[i+1][j-1]) dp[i][j]=true;
            }
        }
    }
    vector<vector<ll>> v(n);
    rep(i,n){
        rep(j,n){
            if(dp[i][j]) v[i].push_back(j);
        }
    }
    vector<vector<bool>> dp2(n+1,vector<bool>(n+1,false));
    dp2[0][n]=true;
    rep(i,n){
        rep(j,n+1){
            if(!dp2[i][j]) continue;
            for(auto &k:v[i]){
                dp2[k+1][min(j,k-i+1)]=true;
            }
        }
    }
    ll ans=1;
    rep(i,n+1){
        if(dp2[n][i]) chmax(ans,i);
    }
    cout << ans << '\n';
}
0