結果
| 問題 |
No.588 空白と回文
|
| コンテスト | |
| ユーザー |
zaichu
|
| 提出日時 | 2017-11-04 00:47:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 960 bytes |
| コンパイル時間 | 1,647 ms |
| コンパイル使用メモリ | 167,756 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-11-23 15:35:35 |
| 合計ジャッジ時間 | 26,674 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / 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 s[l] == ' ' ? cnt : cnt + 1;
if (r - l < 2)
return s[r] == s[l] ? cnt + 2 : cnt;
if ((cnt > 0 && s[l] != s[r]) || (s[l] == ' ' && s[r] == ' '))
return max(dfs(s, l + 1, r - 1, cnt), max(dfs(s, l + 1, r, 0), dfs(s, l, r - 1, 0)));
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;
}
zaichu