結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2015-12-16 11:55:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 503 bytes |
| コンパイル時間 | 1,766 ms |
| コンパイル使用メモリ | 60,156 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-27 12:33:49 |
| 合計ジャッジ時間 | 2,372 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, const char**)’:
main.cpp:25:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | for(int i=0; i<n; ++i) scanf(" %d", &v[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n;
const int N = 1000;
vector<int> v(N);
int dp[1002];
//現在x番目に注目
int rec(int x){
if(x>n) return 0;
if(dp[x]>=0) return dp[x];
//x番目を食べる、食べない
return dp[x] = max( rec(x+2)+v[x], rec(x+1) );
}
int main(int argc, char const *argv[]) {
cin >>n;
for(int i=0; i<n; ++i) scanf(" %d", &v[i]);
fill(dp,dp+n+1,-1);
printf("%d\n", rec(0));
return 0;
}