結果

問題 No.45 回転寿司
ユーザー _oba23_
提出日時 2018-08-18 23:51:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 658 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 65,128 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 19:19:28
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge1 / 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<vector<int>> cache(n+3, vector<int>(2, 0));
    for(int i=n-1; i>=0; --i){
        cache[i][false]=max(
                max(cache[i+1][false], cache[i+1][true]),
                max(cache[i+2][false], cache[i+2][true]));
        cache[i][true]=max(
                max(cache[i+2][false], cache[i+2][true]),
                max(cache[i+3][false], cache[i+3][true]))+v[i];
    }
    cout << max(cache[0][true], cache[0][false]) << endl;
    return 0;
}
0