結果

問題 No.258 回転寿司(2)
ユーザー ldsyb
提出日時 2017-07-22 03:32:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 641 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 72,960 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-09 04:57:02
合計ジャッジ時間 4,614 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 57 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	int n;
	cin >> n;
	int v[n];
	for(int i = 0; i < n; i++) cin >> v[i];
	if(n == 1){
		cout << v[0] << endl;
		cout << 1 << endl;
		return 0;
	}
	int dp[n];
	dp[0] = v[0];
	dp[1] = max(v[0], v[1]);
	for(int i = 2; i < n; i++) dp[i] = max(dp[i - 1], dp[i - 2] + v[i]);
	cout << dp[n - 1] << endl;
	vector<int> ans;
	for(int i = n - 1; 0 <= i; i--){
		if(2 <= i && dp[i] - dp[i - 2] == v[i]) ans.emplace_back(i-- + 1);
	}
	ans.emplace_back((dp[0] != dp[1]) + 1);
	reverse(ans.begin(), ans.end());
	for(int num:ans) cout << num << ' ';
	cout << endl;
}
0