結果
| 問題 | No.588 空白と回文 |
| コンテスト | |
| ユーザー |
zaichu
|
| 提出日時 | 2017-11-04 00:44:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 935 bytes |
| 記録 | |
| コンパイル時間 | 1,609 ms |
| コンパイル使用メモリ | 169,448 KB |
| 実行使用メモリ | 13,640 KB |
| 最終ジャッジ日時 | 2024-11-23 15:34:11 |
| 合計ジャッジ時間 | 26,801 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 3 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 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