結果
問題 | No.588 空白と回文 |
ユーザー |
![]() |
提出日時 | 2022-10-31 20:19:41 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 469 ms / 2,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 7,556 ms |
コンパイル使用メモリ | 140,676 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-08 08:20:54 |
合計ジャッジ時間 | 4,847 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
#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 f(string str) { string rs = str; reverse(rs.begin(), rs.end()); return str == rs; } int g(string str) { int n = str.size(); int i = 0; int j = n - 1; int len = n; while (i < j) { if (str[i] != str[j]) { str[i] = '#'; str[j] = '#'; len -= 2; } ++i; --j; } if (f(str)) { return len; } else { return 0; } } int main() { string S; cin >> S; int N = S.size(); int ans = 0; for (int l = 1; l <= N; ++l) { for (int i = 0; i <= N - l; ++i) { string str = S.substr(i, l); if (f(str)) { ans = l; } ans = max(ans, g(str)); } } cout << ans << endl; return 0; }