Submission #53267478


Source Code Expand

N, M = map(int, input().split())
key = []
for _ in range(M):
    a, b = map(int, input().split())
    s = 0 # i 番目の鍵で開けることのできる宝箱の集合
    c = list(map(lambda x: int(x) - 1, input().split()))
    for i in c:
        s |= (1 << i)
    key.append((a, s))

INF = 10**18
# dp[S] := 集合 S の宝箱を開けるのに必要な費用の最小値
dp = [INF]*(1 << N)
dp[0] = 0
for S in range(1 << N):
    for k, v in key:
        dp[S | v] = min(dp[S | v], dp[S] + k)

if dp[(1 << N) - 1] != INF:
    print(dp[(1 << N) - 1])
else:
    print(-1)

Submission Info

Submission Time
Task E - Get Everything
User ryusuke_h
Language Python (PyPy 3.10-v7.3.12)
Score 500
Code Size 595 Byte
Status AC
Exec Time 104 ms
Memory 82856 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 40
Set Name Test Cases
Sample 00-sample-00, 00-sample-01, 00-sample-02
All 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 01-handmade-07, 02-random-08, 02-random-09, 02-random-10, 02-random-11, 02-random-12, 02-random-13, 02-random-14, 02-random-15, 02-random-16, 02-random-17, 02-random-18, 02-random-19, 02-random-20, 02-random-21, 02-random-22, 02-random-23, 02-random-24, 02-random-25, 02-random-26, 02-random-27, 02-random-28, 02-random-29, 02-random-30, 02-random-31, 02-random-32, 02-random-33, 02-random-34, 02-random-35, 02-random-36, 02-random-37, 02-random-38, 02-random-39
Case Name Status Exec Time Memory
00-sample-00 AC 59 ms 76096 KiB
00-sample-01 AC 64 ms 80500 KiB
00-sample-02 AC 60 ms 76176 KiB
01-handmade-03 AC 82 ms 81844 KiB
01-handmade-04 AC 94 ms 82800 KiB
01-handmade-05 AC 65 ms 81048 KiB
01-handmade-06 AC 68 ms 81020 KiB
01-handmade-07 AC 87 ms 81896 KiB
02-random-08 AC 83 ms 82772 KiB
02-random-09 AC 64 ms 80788 KiB
02-random-10 AC 89 ms 82184 KiB
02-random-11 AC 66 ms 81400 KiB
02-random-12 AC 85 ms 82176 KiB
02-random-13 AC 79 ms 82856 KiB
02-random-14 AC 70 ms 80860 KiB
02-random-15 AC 79 ms 81444 KiB
02-random-16 AC 75 ms 81316 KiB
02-random-17 AC 85 ms 82040 KiB
02-random-18 AC 86 ms 81864 KiB
02-random-19 AC 72 ms 81212 KiB
02-random-20 AC 63 ms 81016 KiB
02-random-21 AC 90 ms 82852 KiB
02-random-22 AC 90 ms 82736 KiB
02-random-23 AC 84 ms 82520 KiB
02-random-24 AC 87 ms 81896 KiB
02-random-25 AC 88 ms 82284 KiB
02-random-26 AC 85 ms 82040 KiB
02-random-27 AC 69 ms 81428 KiB
02-random-28 AC 75 ms 81284 KiB
02-random-29 AC 104 ms 82696 KiB
02-random-30 AC 69 ms 80972 KiB
02-random-31 AC 86 ms 81864 KiB
02-random-32 AC 73 ms 80948 KiB
02-random-33 AC 72 ms 81440 KiB
02-random-34 AC 89 ms 82252 KiB
02-random-35 AC 99 ms 82016 KiB
02-random-36 AC 81 ms 81768 KiB
02-random-37 AC 65 ms 80992 KiB
02-random-38 AC 81 ms 82748 KiB
02-random-39 AC 89 ms 81896 KiB