結果

問題 No.50 おもちゃ箱
ユーザー zimphazimpha
提出日時 2017-12-09 02:31:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 596 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 86,760 KB
実行使用メモリ 76,468 KB
最終ジャッジ日時 2023-09-08 04:52:50
合計ジャッジ時間 5,296 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
75,528 KB
testcase_01 AC 86 ms
76,280 KB
testcase_02 AC 76 ms
75,484 KB
testcase_03 AC 72 ms
71,116 KB
testcase_04 AC 76 ms
71,028 KB
testcase_05 AC 87 ms
76,076 KB
testcase_06 AC 86 ms
76,144 KB
testcase_07 AC 72 ms
70,844 KB
testcase_08 AC 72 ms
70,988 KB
testcase_09 AC 73 ms
70,992 KB
testcase_10 AC 72 ms
71,088 KB
testcase_11 AC 71 ms
71,008 KB
testcase_12 AC 74 ms
70,992 KB
testcase_13 AC 71 ms
70,788 KB
testcase_14 AC 77 ms
75,636 KB
testcase_15 AC 72 ms
71,164 KB
testcase_16 AC 75 ms
75,420 KB
testcase_17 AC 84 ms
76,104 KB
testcase_18 AC 85 ms
76,156 KB
testcase_19 AC 88 ms
76,344 KB
testcase_20 AC 80 ms
75,600 KB
testcase_21 AC 86 ms
76,372 KB
testcase_22 AC 85 ms
76,216 KB
testcase_23 AC 78 ms
75,944 KB
testcase_24 AC 72 ms
71,088 KB
testcase_25 AC 72 ms
71,148 KB
testcase_26 AC 80 ms
75,696 KB
testcase_27 AC 83 ms
76,136 KB
testcase_28 AC 86 ms
76,304 KB
testcase_29 AC 88 ms
76,172 KB
testcase_30 AC 85 ms
76,412 KB
testcase_31 AC 72 ms
70,800 KB
testcase_32 AC 85 ms
76,048 KB
testcase_33 AC 85 ms
76,212 KB
testcase_34 AC 88 ms
76,220 KB
testcase_35 AC 87 ms
76,328 KB
testcase_36 AC 88 ms
76,088 KB
testcase_37 AC 88 ms
76,468 KB
testcase_38 AC 85 ms
76,192 KB
testcase_39 AC 87 ms
76,176 KB
testcase_40 AC 86 ms
76,140 KB
testcase_41 AC 88 ms
76,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
b.sort(reverse=True)

weight = [0] * (1 << n)
for mask in range(1, 1 << n):
  for i in range(n):
    weight[mask] += (mask >> i & 1) * a[i]

f = [False] * (1 << n)
f[0] = True
ret = -1
for i in range(m):
  g = [x for x in f]
  for mask in range(1 << n):
    if not f[mask]: continue
    rest = mask ^ ((1 << n) - 1)
    sub = rest
    while sub:
      if weight[sub] <= b[i]:
        g[mask | sub] = True
      sub = (sub - 1) & rest
  f = g
  if f[-1]:
    ret = i + 1
    break
print(ret)
0