結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー simansiman
提出日時 2023-02-06 19:45:26
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 1,338 ms
コンパイル使用メモリ 106,264 KB
実行使用メモリ 28,388 KB
最終ジャッジ日時 2023-09-18 06:18:12
合計ジャッジ時間 11,375 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
28,012 KB
testcase_01 AC 8 ms
27,988 KB
testcase_02 AC 9 ms
28,000 KB
testcase_03 AC 255 ms
28,272 KB
testcase_04 AC 64 ms
28,108 KB
testcase_05 AC 29 ms
28,116 KB
testcase_06 AC 429 ms
28,324 KB
testcase_07 AC 386 ms
28,336 KB
testcase_08 AC 326 ms
28,336 KB
testcase_09 AC 170 ms
28,284 KB
testcase_10 AC 296 ms
28,328 KB
testcase_11 AC 354 ms
28,320 KB
testcase_12 AC 402 ms
28,388 KB
testcase_13 AC 441 ms
28,352 KB
testcase_14 AC 311 ms
28,324 KB
testcase_15 AC 260 ms
28,320 KB
testcase_16 AC 172 ms
28,276 KB
testcase_17 AC 180 ms
28,308 KB
testcase_18 AC 407 ms
28,316 KB
testcase_19 AC 286 ms
28,356 KB
testcase_20 AC 347 ms
28,352 KB
testcase_21 AC 442 ms
28,360 KB
testcase_22 AC 385 ms
28,352 KB
testcase_23 AC 355 ms
28,308 KB
testcase_24 AC 196 ms
28,316 KB
testcase_25 AC 281 ms
28,360 KB
testcase_26 AC 430 ms
28,308 KB
testcase_27 AC 123 ms
28,252 KB
testcase_28 AC 293 ms
28,352 KB
testcase_29 AC 451 ms
28,312 KB
testcase_30 AC 9 ms
28,000 KB
testcase_31 AC 8 ms
28,072 KB
testcase_32 AC 81 ms
28,312 KB
testcase_33 AC 367 ms
28,312 KB
testcase_34 AC 8 ms
27,992 KB
testcase_35 AC 80 ms
28,256 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) {
    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;
}
0