結果

問題 No.258 回転寿司(2)
ユーザー plasma_eplasma_e
提出日時 2019-01-20 22:29:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,127 ms / 2,000 ms
コード長 843 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 129,068 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 11:39:39
合計ジャッジ時間 26,169 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,124 ms
5,248 KB
testcase_01 AC 1,127 ms
5,376 KB
testcase_02 AC 387 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 175 ms
5,376 KB
testcase_05 AC 219 ms
5,376 KB
testcase_06 AC 725 ms
5,376 KB
testcase_07 AC 73 ms
5,376 KB
testcase_08 AC 202 ms
5,376 KB
testcase_09 AC 94 ms
5,376 KB
testcase_10 AC 13 ms
5,376 KB
testcase_11 AC 120 ms
5,376 KB
testcase_12 AC 179 ms
5,376 KB
testcase_13 AC 62 ms
5,376 KB
testcase_14 AC 654 ms
5,376 KB
testcase_15 AC 86 ms
5,376 KB
testcase_16 AC 80 ms
5,376 KB
testcase_17 AC 81 ms
5,376 KB
testcase_18 AC 813 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 481 ms
5,376 KB
testcase_21 AC 682 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 364 ms
5,376 KB
testcase_27 AC 93 ms
5,376 KB
testcase_28 AC 991 ms
5,376 KB
testcase_29 AC 133 ms
5,376 KB
testcase_30 AC 18 ms
5,376 KB
testcase_31 AC 15 ms
5,376 KB
testcase_32 AC 99 ms
5,376 KB
testcase_33 AC 556 ms
5,376 KB
testcase_34 AC 318 ms
5,376 KB
testcase_35 AC 260 ms
5,376 KB
testcase_36 AC 24 ms
5,376 KB
testcase_37 AC 14 ms
5,376 KB
testcase_38 AC 117 ms
5,376 KB
testcase_39 AC 112 ms
5,376 KB
testcase_40 AC 397 ms
5,376 KB
testcase_41 AC 542 ms
5,376 KB
testcase_42 AC 95 ms
5,376 KB
testcase_43 AC 41 ms
5,376 KB
testcase_44 AC 660 ms
5,376 KB
testcase_45 AC 429 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 449 ms
5,376 KB
testcase_48 AC 33 ms
5,376 KB
testcase_49 AC 85 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 326 ms
5,376 KB
testcase_52 AC 252 ms
5,376 KB
testcase_53 AC 20 ms
5,376 KB
testcase_54 AC 436 ms
5,376 KB
testcase_55 AC 1,022 ms
5,376 KB
testcase_56 AC 398 ms
5,376 KB
testcase_57 AC 33 ms
5,376 KB
testcase_58 AC 265 ms
5,376 KB
testcase_59 AC 840 ms
5,376 KB
testcase_60 AC 8 ms
5,376 KB
testcase_61 AC 513 ms
5,376 KB
testcase_62 AC 92 ms
5,376 KB
testcase_63 AC 377 ms
5,376 KB
testcase_64 AC 941 ms
5,376 KB
testcase_65 AC 393 ms
5,376 KB
testcase_66 AC 3 ms
5,376 KB
testcase_67 AC 614 ms
5,376 KB
testcase_68 AC 661 ms
5,376 KB
testcase_69 AC 476 ms
5,376 KB
testcase_70 AC 75 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<string>
#include<iomanip>
#include<cmath>
#include<stack>
#include<tuple>

int main()
{
	std::map<int, int> map;
	map[0] = -1;
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (int i = 1; i <= N; ++i)
	{
		int V;
		std::cin >> V;
		vec[i - 1] = V;
		for (auto&[sum, prev] : map)
		{
			if (prev < i - 1 && !map.count(sum + V))
			{
				map[sum + V] = i;
			}
		}
	}
	auto[s0, p0] = *map.rbegin();
	auto s = s0;
	auto p = p0;
	std::cout << s << std::endl;
	std::stack<int> stack;
	while (p != -1)
	{
		stack.emplace(p);
		s -= vec[p - 1];
		p = map[s];
	}
	while (stack.size())
	{
		auto t = stack.top();
		stack.pop();
		std::cout << t << " ";
	}
	std::cout << std::endl;
}
0