結果

問題 No.2869 yuusaan's Knapsacks
ユーザー 寝癖寝癖
提出日時 2024-07-19 00:13:06
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,180 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,892 KB
実行使用メモリ 162,896 KB
最終ジャッジ日時 2024-08-04 18:04:28
合計ジャッジ時間 48,273 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
75,660 KB
testcase_01 AC 72 ms
75,464 KB
testcase_02 AC 88 ms
80,524 KB
testcase_03 AC 1,104 ms
112,516 KB
testcase_04 AC 1,077 ms
112,324 KB
testcase_05 AC 71 ms
75,276 KB
testcase_06 AC 2,900 ms
162,420 KB
testcase_07 AC 1,216 ms
111,632 KB
testcase_08 AC 405 ms
95,316 KB
testcase_09 AC 272 ms
95,064 KB
testcase_10 AC 1,507 ms
130,412 KB
testcase_11 AC 861 ms
96,428 KB
testcase_12 AC 2,663 ms
140,164 KB
testcase_13 AC 803 ms
96,664 KB
testcase_14 AC 1,695 ms
115,216 KB
testcase_15 AC 1,220 ms
112,684 KB
testcase_16 AC 1,394 ms
112,128 KB
testcase_17 AC 3,872 ms
149,308 KB
testcase_18 AC 2,762 ms
137,112 KB
testcase_19 AC 2,004 ms
123,620 KB
testcase_20 AC 284 ms
95,332 KB
testcase_21 AC 2,356 ms
124,948 KB
testcase_22 AC 3,527 ms
124,360 KB
testcase_23 AC 781 ms
110,688 KB
testcase_24 AC 3,199 ms
140,380 KB
testcase_25 AC 556 ms
95,972 KB
testcase_26 TLE -
testcase_27 AC 69 ms
75,392 KB
testcase_28 AC 2,540 ms
149,424 KB
testcase_29 AC 2,891 ms
162,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from dataclasses import dataclass

N, M = map(int, input().split())
e = list(map(int, input().split()))
v, w = map(list, zip(*[map(int, input().split()) for _ in range(M)]))

@dataclass
class Data:
    v: int
    use: int
    prev: 'Data'

sum_v, sum_w = [0]*(1<<M), [0]*(1<<M)
for S in range(1<<M):
    for j in range(M):
        if S>>j&1:
            sum_v[S] += v[j]
            sum_w[S] += w[j]

now = [Data(0, 0, None) for _ in range(1<<M)]
for i in range(N):
    nxt = [Data(0, 0, None) for _ in range(1<<M)]
    for S in range(1<<M):
        U = (1<<M)-1-S
        T = U
        while True:
            if sum_w[T] <= e[i] and now[S].v+sum_v[T] > nxt[S|T].v:
                    nxt[S|T].v = now[S].v+sum_v[T]
                    nxt[S|T].use = T
                    nxt[S|T].prev = now[S]
            if T == 0:
                break
            T = (T-1)&U
    now = nxt

m = max(now[S].v for S in range(1<<M))
S = [S for S in range(1<<M) if now[S].v == m][0]
cur = now[S]
ans = []
while cur.prev:
    ans.append([i+1 for i in range(M) if cur.use>>i&1])
    cur = cur.prev
if len(ans) != N:
    ans += [[]]*(N-len(ans))
print(m)
for a in ans[::-1]:
    print(len(a), *a)
0