結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー tnakao0123tnakao0123
提出日時 2023-04-22 22:49:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 45,184 KB
実行使用メモリ 27,904 KB
最終ジャッジ日時 2024-04-25 00:39:06
合計ジャッジ時間 5,969 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 92 ms
21,888 KB
testcase_04 AC 17 ms
12,288 KB
testcase_05 AC 9 ms
9,984 KB
testcase_06 AC 174 ms
27,904 KB
testcase_07 AC 151 ms
26,496 KB
testcase_08 AC 136 ms
25,344 KB
testcase_09 AC 144 ms
25,728 KB
testcase_10 AC 171 ms
27,904 KB
testcase_11 AC 137 ms
25,344 KB
testcase_12 AC 174 ms
27,648 KB
testcase_13 AC 173 ms
27,776 KB
testcase_14 AC 177 ms
27,776 KB
testcase_15 AC 159 ms
26,624 KB
testcase_16 AC 64 ms
18,432 KB
testcase_17 AC 85 ms
20,736 KB
testcase_18 AC 177 ms
27,648 KB
testcase_19 AC 177 ms
27,648 KB
testcase_20 AC 177 ms
27,904 KB
testcase_21 AC 176 ms
27,776 KB
testcase_22 AC 176 ms
27,776 KB
testcase_23 AC 176 ms
27,776 KB
testcase_24 AC 177 ms
27,648 KB
testcase_25 AC 178 ms
27,648 KB
testcase_26 AC 176 ms
27,648 KB
testcase_27 AC 111 ms
23,040 KB
testcase_28 AC 176 ms
27,904 KB
testcase_29 AC 177 ms
27,776 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 133 ms
24,448 KB
testcase_33 AC 176 ms
27,776 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 130 ms
24,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2204.cc:  No.2204 Palindrome Splitting (No Rearrangement ver.) - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 5000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

char s[MAX_N + 4];
bool ps[MAX_N + 1][MAX_N + 1];
int dp[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  for (int i = 0; i <= n; i++) ps[i][i] = true;
  for (int i = 0; i < n; i++) ps[i][i + 1] = true;
  for (int l = 2; l <= n; l++)
    for (int i = 0, j = l; j <= n; i++, j++)
      ps[i][j] = (ps[i + 1][j - 1] && s[i] == s[j - 1]);

  dp[0] = INF;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j <= n; j++)
      if (ps[i][j])
	dp[j] = max(dp[j], min(dp[i], j - i));
  
  printf("%d\n", dp[n]);
  return 0;
}
0