結果

問題 No.588 空白と回文
ユーザー Ut.k
提出日時 2017-11-03 23:09:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 603 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 57,564 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-11-23 14:51:38
合計ジャッジ時間 31,444 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int DFS2(const string &S, int l, int r) {
    if (l > r) {
    return 0;
  }

  if (l == r) {
    return 1;
  }

  return DFS2(S, l + 1, r - 1) + (S[l] == S[r] ? 2 : 0);
}


int DFS(const string &S, int l, int r) {
  if (l > r) {
    return 0;
  }

  if (l == r) {
    return 1;
  }

  int cnt = 0;
  if (S[l] == S[r]) {
    cnt = DFS2(S, l + 1, r - 1) + 2;
  }

  return max(max(DFS(S, l + 1, r), DFS(S, l, r - 1)), cnt);
}

int main() {
  string S;
  cin >> S;

  cout << DFS(S, 0, S.size() - 1) << endl;

  return 0;
}
0