結果
問題 | No.2204 Palindrome Splitting (No Rearrangement ver.) |
ユーザー |
👑 ![]() |
提出日時 | 2023-02-03 21:32:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 1,758 bytes |
コンパイル時間 | 740 ms |
コンパイル使用メモリ | 80,304 KB |
最終ジャッジ日時 | 2025-02-10 08:48:47 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#line 1 "Main.cpp"#include <iostream>#include <string>#include <vector>#include <algorithm>#include <atcoder/modint>#line 1 "nachia\\string\\enumerate-palindromes.hpp"#line 4 "nachia\\string\\enumerate-palindromes.hpp"namespace nachia{std::vector<int> EnumeratePalindromes(const std::string& S) {int n = S.size();if (n == 0) return { 0 };std::string sx(n * 2 + 1, '$');for (int i = 0; i < n; i++) sx[i * 2 + 1] = S[i];n = n * 2 + 1;std::vector<int> res(n);int r = 0;for (int i = 0; i < n; ) {while ((0 <= i - r && i + r < n) ? (sx[i - r] == sx[i + r]) : false) r++;res[i] = r;int di = 1;while ((0 <= i - di && i + di < n) ? (res[i - di] < r - di) : false) {res[i + di] = res[i - di];di++;}r -= di;i += di;}for (int i = 0; i + 1 < n; i++) res[i] = res[i + 1] - 1;res.resize(n - 2);return res;}} // namespace nachia#line 7 "Main.cpp"using namespace std;using i32 = int;using u32 = unsigned int;using i64 = long long;using u64 = unsigned long long;#define rep(i,n) for(int i=0; i<(int)(n); i++)const i64 INF = 1001001001001001001;using Modint = atcoder::static_modint<998244353>;int main(){string S; cin >> S;auto P = nachia::EnumeratePalindromes(S);int N = S.size();vector<int> dp(N+1, -1);dp[0] = 1000000;rep(i,P.size()){for(int c=1-i%2; c<=P[i]; c+=2){int s = (i-c+1)/2;dp[s+c] = max(dp[s+c], min(dp[s], c));}}cout << dp[N] << endl;return 0;}struct ios_do_not_sync{ios_do_not_sync(){ios::sync_with_stdio(false);cin.tie(nullptr);}} ios_do_not_sync_instance;