結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー siman
提出日時 2023-02-06 19:35:22
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 2,294 ms
コンパイル使用メモリ 140,032 KB
実行使用メモリ 132,708 KB
最終ジャッジ日時 2024-07-04 22:26:39
合計ジャッジ時間 9,264 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#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][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][N - 1] != -1) {
    return memo[l][N - 1];
  }
  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][N - 1] = 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) {
      is_kaibun[l][r] = check(l, r);
    }
  }

  cout << dfs(0) << endl;

  return 0;
}
0