結果

問題 No.258 回転寿司(2)
ユーザー tsukio
提出日時 2016-03-25 17:41:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 62,560 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-06 18:59:25
合計ジャッジ時間 3,801 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n;
int memo[1010];
int values[1000];

int CalcMaxValue(int index) {

	if (index >= n)
		return 0;

	if (memo[index] != -1)
		return memo[index];

	int ret = max(
		values[index] + CalcMaxValue(index + 2),
		CalcMaxValue(index + 1));

	memo[index] = ret;

	return ret;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> values[i];
		memo[i] = -1;
	}

	cout << CalcMaxValue(0) << endl;

	vector<int> result;
	
	int i = 0;
	while (i < n)
	{
		if (memo[i] == memo[i + 1]) {
			i++;
			continue;
		}
		result.emplace_back(i + 1);
		i += 2;
	}

	for (int i = 0; i < result.size(); i++) {
		cout << result[i];
		if (i < result.size() - 1)
			cout << " ";
	}
	cout << endl;
	
	return 0;
}
0