結果
問題 |
No.588 空白と回文
|
ユーザー |
![]() |
提出日時 | 2017-11-04 01:16:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 912 bytes |
コンパイル時間 | 1,543 ms |
コンパイル使用メモリ | 167,752 KB |
実行使用メモリ | 12,068 KB |
最終ジャッジ日時 | 2024-11-23 15:47:15 |
合計ジャッジ時間 | 26,490 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 1 TLE * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long lcm(long long x, long long y) { if (x == 0 || y == 0) return 0; return x / gcd(x, y) * y; } int dfs(string s, int l, int r, int cnt) { //cout << s.substr(l, r - l + 1) << endl //<< " " << l << " " << r << " " << cnt << endl; if (l == r && cnt >= 2) return cnt + 1; if (r - l < 2) return s[r] != s[l] ? cnt : cnt + 2; if (cnt > 0 && s[l] != s[r]) return max(max(dfs(s, l + 1, r, 0), dfs(s, l, r - 1, 0)), dfs(s, l + 1, r - 1, cnt)); else if (s[l] == s[r]) return dfs(s, l + 1, r - 1, cnt + 2); else return max(dfs(s, l + 1, r, 0), dfs(s, l, r - 1, 0)); } int main() { string S; cin >> S; int N = S.size(); cout << dfs(S, 0, N - 1, 0) << endl; }