結果

問題 No.45 回転寿司
ユーザー sei0o
提出日時 2017-10-17 13:10:46
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 683 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 590 ms
コンパイル使用メモリ 97,488 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-02 04:56:42
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int dp[1010][2]; // dp[i][k] = i番目までのお寿司でi番目のsushiを取った場合の最大の「うまい!w」

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) cin >> a[i];

    for (int i = 0; i < N; i++) {
        // sushiを取る
        dp[i+1][1] = dp[i][0] + a[i];
        // sushiを取らない
        dp[i+1][0] = max(dp[i][1], dp[i][0]);
    }

    cout << max(dp[N][0], dp[N][1]) << endl;

    return 0;
}
0