結果
問題 |
No.2204 Palindrome Splitting (No Rearrangement ver.)
|
ユーザー |
|
提出日時 | 2023-05-10 04:04:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 266 ms / 2,000 ms |
コード長 | 830 bytes |
コンパイル時間 | 1,485 ms |
コンパイル使用メモリ | 167,252 KB |
実行使用メモリ | 70,144 KB |
最終ジャッジ日時 | 2024-11-26 10:53:01 |
合計ジャッジ時間 | 8,060 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) #define pii pair<int,int> #define vi vector<int> #define fi first #define se second #define pb push_back #define ALL(x) x.begin(),x.end() #define sz(x) int(x.size()) #define ll long long using namespace std; const int N = 5e3 + 5; int n,ok[N][N],dp[N]; char s[N]; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> (s + 1); while(s[n + 1])n++; dp[0] = n; rep(i,1,n)ok[i][i] = 1; rep(len,2,n)rep(i,1,n){ int j = i + len - 1; if(len == 2 && s[i] == s[j])ok[i][j] = 1; if(len > 2 && s[i] == s[j])ok[i][j] = ok[i + 1][j - 1]; } rep(i,1,n)rep(j,1,i){ if(ok[j][i])dp[i] = max(dp[i],min(dp[j - 1],i - j + 1)); } cout << dp[n] << endl; return 0; }