結果
| 問題 |
No.2204 Palindrome Splitting (No Rearrangement ver.)
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-02-06 19:52:07 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 127 ms / 2,000 ms |
| コード長 | 1,150 bytes |
| コンパイル時間 | 1,791 ms |
| コンパイル使用メモリ | 141,008 KB |
| 実行使用メモリ | 28,288 KB |
| 最終ジャッジ日時 | 2024-07-04 22:36:10 |
| 合計ジャッジ時間 | 5,112 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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) {
for (int r = l; r < N; ++r) {
if (0 <= l - 1 && r + 1 < N && is_kaibun[l - 1][r + 1] && S[l] == S[r]) {
is_kaibun[l][r] = true;
} else {
is_kaibun[l][r] = check(l, r);
}
}
}
cout << dfs(0) << endl;
return 0;
}
siman