結果

問題 No.588 空白と回文
ユーザー simansiman
提出日時 2022-10-31 20:19:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 542 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 4,228 ms
コンパイル使用メモリ 106,244 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 16:54:27
合計ジャッジ時間 8,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

bool f(string str) {
  string rs = str;
  reverse(rs.begin(), rs.end());

  return str == rs;
}

int g(string str) {
  int n = str.size();
  int i = 0;
  int j = n - 1;
  int len = n;

  while (i < j) {
    if (str[i] != str[j]) {
      str[i] = '#';
      str[j] = '#';
      len -= 2;
    }
    ++i;
    --j;
  }

  if (f(str)) {
    return len;
  } else {
    return 0;
  }
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;

  for (int l = 1; l <= N; ++l) {
    for (int i = 0; i <= N - l; ++i) {
      string str = S.substr(i, l);

      if (f(str)) {
        ans = l;
      }
      ans = max(ans, g(str));
    }
  }

  cout << ans << endl;

  return 0;
}
0