結果
問題 | No.127 門松もどき |
ユーザー |
|
提出日時 | 2016-09-14 20:18:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 64 ms / 5,000 ms |
コード長 | 1,245 bytes |
コンパイル時間 | 1,630 ms |
コンパイル使用メモリ | 167,408 KB |
実行使用メモリ | 50,316 KB |
最終ジャッジ日時 | 2024-12-23 22:33:37 |
合計ジャッジ時間 | 3,173 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<<endl #define smax(x,y) (x)=max((x),(y)) #define smin(x,y) (x)=min((x),(y)) #define MEM(x,y) memset((x),(y),sizeof (x)) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; int N, A[3001], dp[3001][3001][2]; int main(){ cin >> N; rep(i, N)scanf("%d", &A[i]); rep(i, N)rep(j, 2)dp[i][i][j] = 1; int ans = 1; rep(len, N){ rep(l, N-len){ int r = l + len; rep(lr, 2){ int val = dp[l][r][lr]; if(lr == 0 && l > 0){ smax(dp[l-1][r][lr], val); if(A[r] > A[l - 1])smax(dp[l - 1][r][!lr], val + 1), smax(ans, val + 1); } if(lr == 1 && r < N-1){ smax(dp[l][r+1][lr], val); if(A[l] > A[r + 1])smax(dp[l][r + 1][!lr], val + 1), smax(ans, val + 1); } } } } cout << ans << endl; }