結果

問題 No.45 回転寿司
ユーザー siguma323
提出日時 2016-05-05 15:21:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 673 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 13:19:47
合計ジャッジ時間 1,825 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <utility>
#include <cmath>
#include <map>
#include <unordered_map>
#include <functional>
#include <fstream>
using namespace std;

using ull = unsigned long long;

int main()
{
    int dp[1001];
    int n;
    cin >> n;
    vector<int> V(n);

    for(auto&& x : V)
    {
        cin >> x;
    }

    if(n == 1)
    {
        cout << V.at(0) << endl;
        return 0;
    }

    dp[0] = V.at(0);
    dp[1] = max(dp[0],V.at(1));

    for(int i = 2; i < n; ++i)
    {
        dp[i] = max(dp[i-1],dp[i-2] + V.at(i));
    }

    cout << dp[n-1] << endl;
}
0