結果
問題 |
No.588 空白と回文
|
ユーザー |
![]() |
提出日時 | 2017-11-03 22:50:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 434 ms / 2,000 ms |
コード長 | 1,971 bytes |
コンパイル時間 | 1,955 ms |
コンパイル使用メモリ | 167,068 KB |
実行使用メモリ | 8,448 KB |
最終ジャッジ日時 | 2024-11-22 16:13:17 |
合計ジャッジ時間 | 5,307 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
#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; }