結果

問題 No.588 空白と回文
ユーザー Ut.kUt.k
提出日時 2017-11-03 23:09:41
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 603 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 57,464 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-05-02 20:35:50
合計ジャッジ時間 3,964 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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