結果
| 問題 | No.127 門松もどき |
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-16 19:12:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 966 bytes |
| 記録 | |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 35,840 KB |
| 実行使用メモリ | 72,132 KB |
| 最終ジャッジ日時 | 2024-06-28 23:06:51 |
| 合計ジャッジ時間 | 3,370 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:33:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d", A+i);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstring>
#include <algorithm>
int N, A[3001];
int dp[2][3001][3001];
int rec(int l, int r, int p){
if(l == r){return 0;}
if(~dp[p][l][r]){return dp[p][l][r];}
int res = 0;
if(p == 0){ // 左はとったぞ
res = std::max(res, rec(l, r-1, p));
if(A[l] < A[r]){
res = std::max({res, 1 + rec(l+1, r, !p)});
}
}else{ // 右はとったぞ
res = std::max(res, rec(l+1, r, p));
if(A[r] < A[l]){
res = std::max(res, 1 + rec(l, r-1, !p));
}
}
// printf("%d %d %d: %d\n", l, r, p, res);
return dp[p][l][r] = res;
}
int main(){
scanf("%d", &N);
for(int i=1;i<=N;i++){
scanf("%d", A+i);
}
memset(dp, -1, sizeof(dp));
int res = 0;
for(int i=1;i<=N;i++){
for(int j=i+1;j<=N;j++){
res = std::max({res, 1 + rec(i, j, 0), 1 + rec(i, j, 1)});
}
}
printf("%d\n", res);
}
tottoripaper