結果
問題 |
No.2204 Palindrome Splitting (No Rearrangement ver.)
|
ユーザー |
![]() |
提出日時 | 2023-01-28 12:38:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 892 bytes |
コンパイル時間 | 1,180 ms |
コンパイル使用メモリ | 113,504 KB |
最終ジャッジ日時 | 2025-02-10 07:28:31 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> #include <complex> #include <cassert> using namespace std; int main(){ string S; cin >> S; assert(S.size() <= 5000); for (auto x : S) assert('a' <= x && x <= 'z'); reverse(S.begin(), S.end()); int N = S.size(); vector<vector<bool>> ok(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]); } } vector<int> dp(N+1); dp[0] = 1e9; for (int i=1; i<=N; i++){ for (int j=0; j<i; j++){ if (ok[j+1][i]) dp[i] = max(dp[i], min(dp[j], i-j)); } } cout << dp[N] << endl; return 0; }