結果

問題 No.527 ナップサック容量問題
ユーザー さかぽんさかぽん
提出日時 2021-05-18 10:50:23
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 106,880 KB
実行使用メモリ 17,948 KB
最終ジャッジ日時 2024-04-17 00:09:53
合計ジャッジ時間 3,598 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
17,792 KB
testcase_01 AC 26 ms
17,792 KB
testcase_02 AC 27 ms
17,792 KB
testcase_03 AC 27 ms
17,920 KB
testcase_04 AC 27 ms
17,792 KB
testcase_05 AC 33 ms
17,884 KB
testcase_06 AC 49 ms
17,824 KB
testcase_07 AC 41 ms
17,692 KB
testcase_08 AC 31 ms
17,752 KB
testcase_09 AC 27 ms
17,792 KB
testcase_10 AC 49 ms
17,700 KB
testcase_11 AC 36 ms
17,692 KB
testcase_12 AC 32 ms
17,632 KB
testcase_13 AC 51 ms
17,948 KB
testcase_14 AC 30 ms
17,624 KB
testcase_15 AC 35 ms
17,812 KB
testcase_16 AC 27 ms
17,536 KB
testcase_17 AC 32 ms
17,628 KB
testcase_18 AC 35 ms
17,808 KB
testcase_19 AC 26 ms
17,792 KB
testcase_20 AC 30 ms
17,756 KB
testcase_21 AC 55 ms
17,840 KB
testcase_22 AC 41 ms
17,820 KB
testcase_23 AC 54 ms
17,836 KB
testcase_24 AC 28 ms
17,792 KB
testcase_25 AC 39 ms
17,940 KB
testcase_26 AC 37 ms
17,812 KB
testcase_27 AC 37 ms
17,812 KB
testcase_28 AC 34 ms
17,796 KB
testcase_29 AC 55 ms
17,704 KB
testcase_30 AC 26 ms
17,792 KB
testcase_31 AC 31 ms
17,760 KB
testcase_32 AC 33 ms
17,676 KB
testcase_33 AC 32 ms
17,760 KB
testcase_34 AC 34 ms
17,684 KB
testcase_35 AC 37 ms
17,816 KB
testcase_36 AC 27 ms
17,664 KB
testcase_37 AC 31 ms
17,760 KB
testcase_38 AC 35 ms
17,816 KB
testcase_39 AC 33 ms
17,824 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class C
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		var n = int.Parse(Console.ReadLine());
		var ps = Array.ConvertAll(new bool[n], _ => Read2());
		var mv = int.Parse(Console.ReadLine());

		var mw = 1000 * n;
		var dp = Array.ConvertAll(new bool[mw + 2], _ => -1);
		dp[0] = 0;

		foreach (var (v, w) in ps)
		{
			for (int i = mw; i >= w; i--)
			{
				if (dp[i - w] == -1) continue;
				dp[i] = Math.Max(dp[i], dp[i - w] + v);
			}
		}

		var min = mv == 0 ? 1 : Array.IndexOf(dp, mv);
		var max = min;
		while (max <= mw && dp[max + 1] <= mv) max++;

		return $"{min}\n{(max == dp.Length - 1 ? "inf" : max.ToString())}";
	}
}
0