結果

問題 No.588 空白と回文
ユーザー T1610T1610
提出日時 2017-11-03 22:50:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,971 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 164,896 KB
実行使用メモリ 8,540 KB
最終ジャッジ日時 2023-08-14 17:11:04
合計ジャッジ時間 4,051 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 276 ms
8,276 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 275 ms
8,348 KB
testcase_12 AC 271 ms
8,540 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 134 ms
7,252 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 274 ms
8,484 KB
testcase_21 AC 191 ms
7,736 KB
testcase_22 AC 263 ms
8,412 KB
testcase_23 AC 116 ms
7,164 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


int dp[1010][1010];
bool used[1010][1010];
string s;
int n;

int calc(int l, int r) {
    if(r - l == 0) return 0;
    if(used[l][r]) return dp[l][r];
    used[l][r] = true;
    auto& ret = dp[l][r];
    if(s[l] == s[r-1]) ret = max(ret, 2);
    for(int a = l+1, b = r-1; a < b; a++, b--) {
        ret = max(ret, calc(a, b)+(s[l]==s[r-1] ? 2 : 0));
    }
    // REP(i, l+1, r) {
    //     if(s[l] == s[i]) {
    //         ret = max(ret, calc(l+1, i)+2);
    //     }
    // }
    return ret;
}

int main(){
    cin >> s;
    n = s.size();
    rep(i, n) dp[i][i+1] = 1, used[i][i+1] = true;
    int ans = 0;
    rep(i, n) REP(j, i+1, n+1) {
        ans = max(ans, calc(i, j));
    }
    cout << ans << endl;
    #ifdef DEBUG_MODE
    //DEBUG_2D
    for(int i = 0; i < n+1; i++) {
        for(int j = 0; j < n+1; j++) printf("%3d",dp[i][j]);
        printf("\n");
    }
    #endif
    return 0;
}
0