結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー simansiman
提出日時 2023-02-06 19:35:22
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,040 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 103,552 KB
実行使用メモリ 126,460 KB
最終ジャッジ日時 2023-09-18 06:10:23
合計ジャッジ時間 9,569 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
126,064 KB
testcase_01 AC 44 ms
126,104 KB
testcase_02 AC 35 ms
126,008 KB
testcase_03 AC 65 ms
126,264 KB
testcase_04 AC 43 ms
126,144 KB
testcase_05 AC 41 ms
126,068 KB
testcase_06 AC 97 ms
126,328 KB
testcase_07 AC 79 ms
126,324 KB
testcase_08 AC 76 ms
126,316 KB
testcase_09 AC 142 ms
126,316 KB
testcase_10 AC 107 ms
126,380 KB
testcase_11 AC 72 ms
126,316 KB
testcase_12 AC 83 ms
126,340 KB
testcase_13 AC 81 ms
126,344 KB
testcase_14 AC 99 ms
126,344 KB
testcase_15 AC 116 ms
126,432 KB
testcase_16 AC 51 ms
126,216 KB
testcase_17 AC 62 ms
126,324 KB
testcase_18 AC 85 ms
126,348 KB
testcase_19 AC 112 ms
126,460 KB
testcase_20 AC 93 ms
126,332 KB
testcase_21 AC 84 ms
126,376 KB
testcase_22 AC 88 ms
126,376 KB
testcase_23 AC 95 ms
126,380 KB
testcase_24 AC 152 ms
126,376 KB
testcase_25 AC 112 ms
126,448 KB
testcase_26 AC 81 ms
126,444 KB
testcase_27 AC 104 ms
126,284 KB
testcase_28 AC 105 ms
126,344 KB
testcase_29 AC 82 ms
126,344 KB
testcase_30 AC 31 ms
126,020 KB
testcase_31 AC 32 ms
126,020 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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