結果

問題 No.45 回転寿司
ユーザー syutaro
提出日時 2017-06-24 00:10:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 69,376 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-03 03:57:15
合計ジャッジ時間 1,636 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <algorithm>
#define rep(i, n) for(int (i)=0; (i)<(n); ++(i))
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> val = vector<int>(n);
    vector<int> ans = vector<int>(n);
    rep(i,n) {
        int x;
        cin >> x;
        val[i] = x;
        ans[i] = 0;
    }
    ans[0] = val[0];
    ans[1] = max(val[0], val[1]);

    for(int i=3; i<n; ++i) {
        ans[i] = max(ans[i-2] + val[i], ans[i-1]);
    }

    cout << ans[n-1] << endl;
	return 0;
}
0