結果
問題 |
No.2204 Palindrome Splitting (No Rearrangement ver.)
|
ユーザー |
![]() |
提出日時 | 2023-04-22 22:49:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 866 bytes |
コンパイル時間 | 434 ms |
コンパイル使用メモリ | 43,776 KB |
実行使用メモリ | 27,264 KB |
最終ジャッジ日時 | 2024-11-07 10:03:27 |
合計ジャッジ時間 | 4,972 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
/* -*- 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; }