結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー simansiman
提出日時 2023-02-06 19:52:07
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,150 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 104,660 KB
実行使用メモリ 28,400 KB
最終ジャッジ日時 2023-09-18 06:23:09
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
28,048 KB
testcase_01 AC 8 ms
28,040 KB
testcase_02 AC 8 ms
28,088 KB
testcase_03 AC 40 ms
28,272 KB
testcase_04 AC 16 ms
28,192 KB
testcase_05 AC 14 ms
28,088 KB
testcase_06 AC 63 ms
28,364 KB
testcase_07 AC 57 ms
28,312 KB
testcase_08 AC 54 ms
28,288 KB
testcase_09 AC 111 ms
28,292 KB
testcase_10 AC 82 ms
28,312 KB
testcase_11 AC 52 ms
28,384 KB
testcase_12 AC 63 ms
28,316 KB
testcase_13 AC 62 ms
28,312 KB
testcase_14 AC 77 ms
28,352 KB
testcase_15 AC 91 ms
28,320 KB
testcase_16 AC 29 ms
28,204 KB
testcase_17 AC 40 ms
28,320 KB
testcase_18 AC 64 ms
28,368 KB
testcase_19 AC 88 ms
28,300 KB
testcase_20 AC 73 ms
28,360 KB
testcase_21 AC 62 ms
28,400 KB
testcase_22 AC 66 ms
28,336 KB
testcase_23 AC 73 ms
28,304 KB
testcase_24 AC 125 ms
28,316 KB
testcase_25 AC 87 ms
28,292 KB
testcase_26 AC 62 ms
28,364 KB
testcase_27 AC 81 ms
28,248 KB
testcase_28 AC 82 ms
28,352 KB
testcase_29 AC 62 ms
28,352 KB
testcase_30 AC 8 ms
27,996 KB
testcase_31 AC 9 ms
28,044 KB
testcase_32 AC 66 ms
28,344 KB
testcase_33 AC 70 ms
28,308 KB
testcase_34 AC 8 ms
28,044 KB
testcase_35 AC 66 ms
28,324 KB
権限があれば一括ダウンロードができます

ソースコード

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];
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;
}
0