結果

問題 No.273 回文分解
ユーザー alpha_virginis
提出日時 2015-08-28 22:37:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 989 bytes
コンパイル時間 1,367 ms
コンパイル使用メモリ 159,992 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-12-23 11:48:46
合計ジャッジ時間 11,471 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdint>
#include <sys/time.h>

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

const unsigned long mod = 1000000007;

std::string str;

bool check(int begin, int end2) {
  for(int i = begin; i <= end2; ++i) {
    if( str[i] != str[begin + end2 - i] ) return false;
  }
  return true;
}

bool ispa[64][64];
int N;

int dfs(int begin, int max) {
  if( ispa[begin][N-1] ) return std::max(max, N-1-begin+1);
  for(int next = begin; next < N-1; ++next) {
    if( ispa[begin][next] ) {
      max = std::max(max, next - begin + 1);
      max = std::max(max, dfs(next+1, max));
    }
  }
  return max;
}

int main() {

  std::cin >> str;
  std::vector<std::string> vstr;
  N = str.size();

  for(int i = 0; i < N; ++i) {
    for(int j = i; j < N; ++j) {
      ispa[i][j] = check(i, j);
    }
  }
  ispa[0][N-1] = false;

  std::cout << dfs(0, 0) << std::endl;
    
  return 0;
}

0