結果

問題 No.258 回転寿司(2)
ユーザー plasma_eplasma_e
提出日時 2019-01-20 22:29:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,135 ms / 2,000 ms
コード長 843 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 128,392 KB
実行使用メモリ 4,860 KB
最終ジャッジ日時 2023-08-06 16:24:33
合計ジャッジ時間 28,818 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,061 ms
4,720 KB
testcase_01 AC 1,056 ms
4,712 KB
testcase_02 AC 420 ms
4,384 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 184 ms
4,376 KB
testcase_05 AC 236 ms
4,376 KB
testcase_06 AC 780 ms
4,588 KB
testcase_07 AC 77 ms
4,376 KB
testcase_08 AC 214 ms
4,376 KB
testcase_09 AC 100 ms
4,380 KB
testcase_10 AC 14 ms
4,380 KB
testcase_11 AC 131 ms
4,376 KB
testcase_12 AC 191 ms
4,376 KB
testcase_13 AC 65 ms
4,376 KB
testcase_14 AC 697 ms
4,512 KB
testcase_15 AC 92 ms
4,380 KB
testcase_16 AC 83 ms
4,376 KB
testcase_17 AC 89 ms
4,380 KB
testcase_18 AC 870 ms
4,860 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 489 ms
4,380 KB
testcase_21 AC 732 ms
4,524 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 391 ms
4,432 KB
testcase_27 AC 97 ms
4,376 KB
testcase_28 AC 1,064 ms
4,696 KB
testcase_29 AC 143 ms
4,380 KB
testcase_30 AC 19 ms
4,380 KB
testcase_31 AC 16 ms
4,376 KB
testcase_32 AC 96 ms
4,376 KB
testcase_33 AC 593 ms
4,380 KB
testcase_34 AC 340 ms
4,380 KB
testcase_35 AC 276 ms
4,376 KB
testcase_36 AC 26 ms
4,380 KB
testcase_37 AC 16 ms
4,376 KB
testcase_38 AC 128 ms
4,376 KB
testcase_39 AC 116 ms
4,376 KB
testcase_40 AC 393 ms
4,380 KB
testcase_41 AC 580 ms
4,420 KB
testcase_42 AC 94 ms
4,380 KB
testcase_43 AC 44 ms
4,376 KB
testcase_44 AC 704 ms
4,564 KB
testcase_45 AC 456 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 480 ms
4,380 KB
testcase_48 AC 37 ms
4,380 KB
testcase_49 AC 93 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 353 ms
4,376 KB
testcase_52 AC 271 ms
4,380 KB
testcase_53 AC 21 ms
4,376 KB
testcase_54 AC 452 ms
4,376 KB
testcase_55 AC 1,135 ms
4,780 KB
testcase_56 AC 424 ms
4,380 KB
testcase_57 AC 36 ms
4,376 KB
testcase_58 AC 282 ms
4,376 KB
testcase_59 AC 894 ms
4,716 KB
testcase_60 AC 9 ms
4,376 KB
testcase_61 AC 528 ms
4,380 KB
testcase_62 AC 100 ms
4,380 KB
testcase_63 AC 398 ms
4,376 KB
testcase_64 AC 1,019 ms
4,704 KB
testcase_65 AC 423 ms
4,396 KB
testcase_66 AC 3 ms
4,376 KB
testcase_67 AC 648 ms
4,444 KB
testcase_68 AC 718 ms
4,692 KB
testcase_69 AC 503 ms
4,380 KB
testcase_70 AC 81 ms
4,380 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