結果

問題 No.588 空白と回文
ユーザー beetbeet
提出日時 2018-07-27 15:27:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 163,888 KB
実行使用メモリ 13,300 KB
最終ジャッジ日時 2023-09-13 18:53:15
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,056 KB
testcase_01 AC 6 ms
13,044 KB
testcase_02 AC 6 ms
12,996 KB
testcase_03 AC 11 ms
13,132 KB
testcase_04 AC 6 ms
13,168 KB
testcase_05 AC 5 ms
13,040 KB
testcase_06 AC 5 ms
12,984 KB
testcase_07 AC 5 ms
12,984 KB
testcase_08 AC 6 ms
13,288 KB
testcase_09 AC 6 ms
13,040 KB
testcase_10 AC 6 ms
13,300 KB
testcase_11 AC 11 ms
13,072 KB
testcase_12 AC 11 ms
13,056 KB
testcase_13 AC 6 ms
13,052 KB
testcase_14 AC 6 ms
12,988 KB
testcase_15 AC 6 ms
12,984 KB
testcase_16 AC 6 ms
13,284 KB
testcase_17 AC 9 ms
13,176 KB
testcase_18 AC 6 ms
12,996 KB
testcase_19 AC 6 ms
12,984 KB
testcase_20 AC 11 ms
13,004 KB
testcase_21 AC 10 ms
13,016 KB
testcase_22 AC 11 ms
13,124 KB
testcase_23 AC 9 ms
13,056 KB
testcase_24 AC 6 ms
12,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int dp[1111][1111];
string s;
Int n;
// [l, r]
Int dfs(Int l,Int r){
  Int &res=dp[l][r];
  if(~res) return res;
  res=(s[l]==s[r])*(1+(l!=r));
  if(l+1<=r-1) res+=dfs(l+1,r-1);
  return res;
}

signed main(){
  cin>>s;
  n=s.size();
  Int ans=0;
  memset(dp,-1,sizeof(dp));
  for(Int i=0;i<n;i++)
    for(Int j=i;j<n;j++)
      chmax(ans,dfs(i,j));
  cout<<ans<<endl;
  return 0;
}
0