結果

問題 No.45 回転寿司
ユーザー めうめう🎒
提出日時 2016-07-05 23:30:55
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 669 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 733 ms
コンパイル使用メモリ 96,372 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-02 03:18:16
合計ジャッジ時間 2,577 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int sushi[1010] = {};
int n;
int memo[1010];

int dp(int now){
	if(now >= n) return 0;
	if(memo[now] != INF) return memo[now];

	int a,b;
	a = dp(now + 1);
	b = dp(now + 2) + sushi[now];

	return memo[now] = max(a,b);
}

int main() {
	for(int i = 0;i < 1010;i++){
		memo[i] = INF;
	}
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> sushi[i];
	}

	cout << dp(0) << endl;
	return 0;
}
0