結果

問題 No.45 回転寿司
ユーザー fushime2
提出日時 2017-12-29 21:53:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 504 bytes
コンパイル時間 2,910 ms
コンパイル使用メモリ 159,740 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 17:49:49
合計ジャッジ時間 4,055 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define mset(a,x) memset(a,x,sizeof(a))

int N;
vector<int> V;

int dp[1010][2];
int rec(int i, bool fetched) {
    int &r = dp[i][fetched];
    if (r != -1) return r;
    if (i == N) return r = 0;
    if (fetched)
        return r = rec(i + 1, 0);
    else
        return r = max(rec(i + 1, 1) + V[i], rec(i + 1, 0));
}

int main() {
    cin >> N; V.resize(N);
    for (int& v : V) cin >> v;
    mset(dp, -1);
    cout << rec(0, 0) << endl;
    return 0;
}
0