結果

問題 No.45 回転寿司
ユーザー lmxyue
提出日時 2025-08-12 17:51:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 573 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 73,660 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-12 17:51:22
合計ジャッジ時間 2,307 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <fstream>
#include <sstream>
using namespace std;
typedef long long ll;

int N;
int V[1010];

bool done[1010];
int dp[1010];

int solve(int k){
    if(k >= N)return 0;
    if(done[k])return dp[k];
    
    int res = max(solve(k + 1), V[k] + solve(k + 2));
    
    done[k] = true;
    return dp[k] = res;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++)cin >> V[i];
    
    cout << solve(0) << endl;
    return 0;
}
0