結果
問題 | No.626 Randomized 01 Knapsack |
ユーザー | wajima_wataru |
提出日時 | 2017-12-31 10:20:00 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 685 bytes |
コンパイル時間 | 99 ms |
コンパイル使用メモリ | 10,960 KB |
実行使用メモリ | 10,176 KB |
最終ジャッジ日時 | 2023-08-23 12:22:23 |
合計ジャッジ時間 | 2,676 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
7,764 KB |
testcase_01 | AC | 17 ms
7,812 KB |
testcase_02 | AC | 17 ms
7,872 KB |
testcase_03 | AC | 18 ms
8,312 KB |
testcase_04 | AC | 20 ms
8,312 KB |
testcase_05 | AC | 19 ms
8,456 KB |
testcase_06 | AC | 74 ms
8,396 KB |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
ソースコード
N, W = map(int, input().split()) VW = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[0]/x[1], reverse=True) SUM_V = [0 for _ in range(N)] cur_sum = 0 for i in range(N - 1, -1, -1): cur_sum += VW[i][0] SUM_V[i] = cur_sum ans = 0 def culc(cur_i, cur_v, cur_w): global ans ans = max(ans, cur_v) if cur_i == N or cur_v + SUM_V[cur_i] < ans: return i = cur_i v = cur_v w = cur_w while i < N and w + VW[i][1] < W: v += VW[i][0] w += VW[i][1] if v + VW[i][0] * (W - w) / VW[i][1] <= ans: return if cur_w + VW[cur_i][1] <= W: culc(cur_i + 1, cur_v + VW[cur_i][0], cur_w + VW[cur_i][1]) culc(cur_i + 1, cur_v, cur_w) culc(0, 0, 0) print(ans)