結果
問題 | No.273 回文分解 |
ユーザー | alpha_virginis |
提出日時 | 2015-08-28 22:40:16 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,128 bytes |
コンパイル時間 | 1,537 ms |
コンパイル使用メモリ | 160,816 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 13:24:50 |
合計ジャッジ時間 | 2,342 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> #include <cstdint> #include <sys/time.h> typedef std::int_fast32_t s32; typedef std::uint_fast32_t u32; typedef std::int_fast64_t s64; typedef std::uint_fast64_t u64; const unsigned long mod = 1000000007; std::string str; bool check(int begin, int end2) { for(int i = begin; i <= end2; ++i) { if( str[i] != str[begin + end2 - i] ) return false; } return true; } bool ispa[64][64]; int N; int memo[64]; int dfs(int begin, int max) { if( ispa[begin][N-1] ) return std::max(max, N-1-begin+1); if( memo[begin] >= max ) return memo[begin]; for(int next = N-2; next >= begin; --next) { if( ispa[begin][next] ) { max = std::max(max, next - begin + 1); max = std::max(max, dfs(next+1, max)); } } memo[begin] = max; return max; } int main() { std::cin >> str; std::vector<std::string> vstr; N = str.size(); for(int i = 0; i < 64; ++i) { memo[i] = -1; } for(int i = 0; i < N; ++i) { for(int j = i; j < N; ++j) { ispa[i][j] = check(i, j); } } ispa[0][N-1] = false; std::cout << dfs(0, 0) << std::endl; return 0; }