結果

問題 No.45 回転寿司
ユーザー DialBird
提出日時 2017-02-09 10:51:33
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 611 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 63,200 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 16:03:49
合計ジャッジ時間 1,642 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

#define REP(i,first,last) for (int i=first;i<last;i++)
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)

const int MAX_N = 1000;
const int MAX_V = 100;
int N;
vector<int> v_list;
vector<int> dp(MAX_N + 1, -1);

int solve(int idx){
  if (idx >= N) return 0;
  if (dp[idx] != -1) return dp[idx];

  return dp[idx] = MAX(solve(idx + 1), solve(idx + 2) + v_list[idx]);
}

int main(){
  cin >> N;

  int val;
  REP(i,0,N){
    cin >> val;
    v_list.push_back(val);
  }

  cout << solve(0) << endl;
}
0