結果
問題 |
No.2204 Palindrome Splitting (No Rearrangement ver.)
|
ユーザー |
![]() |
提出日時 | 2023-02-06 19:45:26 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 458 ms / 2,000 ms |
コード長 | 1,142 bytes |
コンパイル時間 | 4,148 ms |
コンパイル使用メモリ | 142,816 KB |
実行使用メモリ | 28,324 KB |
最終ジャッジ日時 | 2024-07-04 22:32:11 |
合計ジャッジ時間 | 11,142 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <climits> #include <map> #include <queue> #include <set> #include <cstring> #include <vector> using namespace std; typedef long long ll; bool is_kaibun[5010][5010]; string S; int memo[5010]; int N; bool check(int l, int r) { int i = l; int j = r; while (i < j) { if (S[i] != S[j]) return false; ++i; --j; } return true; } int dfs(int l) { if (memo[l] != -1) { return memo[l]; } if (l >= N) return 9999; int res = 1; for (int r = l; r < N; ++r) { if (not is_kaibun[l][r]) continue; int len = r - l + 1; res = max(res, min(len, dfs(r + 1))); } return memo[l] = res; } int main() { memset(is_kaibun, false, sizeof(is_kaibun)); memset(memo, -1, sizeof(memo)); cin >> S; N = S.size(); for (int l = 0; l < N; ++l) { set<int> M; for (int r = l; r < N; ++r) { M.insert(S[r] - 'a'); if (M.size() == 1) { is_kaibun[l][r] = true; } else { is_kaibun[l][r] = check(l, r); } } } cout << dfs(0) << endl; return 0; }