結果

問題 No.527 ナップサック容量問題
ユーザー 👑 tatt61880tatt61880
提出日時 2021-04-15 23:06:37
言語 Kuin
(KuinC++ v.2021.9.17)
結果
WA  
実行時間 -
コード長 1,335 bytes
コンパイル時間 2,510 ms
コンパイル使用メモリ 152,488 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-14 18:26:24
合計ジャッジ時間 5,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 45 ms
4,352 KB
testcase_06 AC 244 ms
4,352 KB
testcase_07 WA -
testcase_08 AC 32 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 WA -
testcase_11 AC 91 ms
4,352 KB
testcase_12 AC 55 ms
4,352 KB
testcase_13 AC 252 ms
4,352 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,352 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 13 ms
4,348 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 8 ms
4,348 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 WA -
testcase_36 AC 2 ms
4,356 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
out.cpp: 関数 ‘int64_t k_bj(int64_t, std::shared_ptr<Array_<long int> >, std::shared_ptr<Array_<long int> >, int64_t)’ 内:
out.cpp:1854:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
 1854 | }
      | ^

ソースコード

diff #

func main()
	var n: int :: cui@inputInt()
	var v: []int :: #[n]int
	var w: []int :: #[n]int
	var vSum: int :: 0
	var wSum: int :: 0
	for i(0, n - 1)
		do v[i] :: cui@inputInt()
		do w[i] :: cui@inputInt()
		do vSum :+ v[i]
		do wSum :+ w[i]
	end for
	var val: int :: cui@inputInt()
	
	var ansMin: int
	var ansMax: int
	block
		var ok: int :: 0
		var ng: int :: wSum + 1
		while((ok - ng).abs() > 1)
			var mid: int :: (ok + ng) / 2
			if(f(n, v, w, mid) < val)
				do ok :: mid
			else
				do ng :: mid
			end if
		end while
		do ansMin :: ok + 1
	end block
	block
		var ok: int :: 0
		var ng: int :: wSum + 1
		while((ok - ng).abs() > 1)
			var mid: int :: (ok + ng) / 2
			if(f(n, v, w, mid) <= val)
				do ok :: mid
			else
				do ng :: mid
			end if
		end while
		do ansMax :: ok
	end block
	do cui@print("\{ansMin}\n")
	do cui@print("\{vSum = val ?("inf", "\{ansMax}")}\n")
	
	func f(n: int, v: []int, w: []int, weight: int): int
		; dp[i] = v
		; i 重さの和
		; 価値の最大値
		var dp: []int :: #[weight + 1]int
		do dp[0] :: 1
		for j(0, n - 1)
			for i(weight, 0, -1)
				if(dp[i] <> 0 & i + w[j] <= weight)
					do dp[i + w[j]] :: lib@max(dp[i + w[j]], dp[i] + v[j])
				end if
			end for
		end for
		var res: int :: 0
		for i(weight, 0, -1)
			if(dp[i] <> 0)
				ret dp[i] - 1
			end if
		end for
	end func
end func
0