結果

問題 No.45 回転寿司
ユーザー _oba23_
提出日時 2018-08-18 23:59:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 361 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 61,416 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 19:16:06
合計ジャッジ時間 2,039 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; ++i){
        cin >> v[i];
    }
    vector<int> cache(n+2, 0);
    for(int i=n-1; i>=0; --i){
        cache[i]=max(cache[i+1], cache[i+2]+v[i]);
    }
    cout << cache[0] << endl;
    return 0;
}
0