結果

問題 No.3158 Collect Stamps
ユーザー titia
提出日時 2025-06-01 01:15:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 481 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 192,364 KB
最終ジャッジ日時 2025-06-01 01:15:34
合計ジャッジ時間 6,175 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from heapq import heappop,heappush

N,M,K=map(int,input().split())
A=list(map(int,input().split()))
T=[list(map(int,input().split())) for i in range(N)]

for i in range(K):
    A[i]-=1

ANS=1<<60

for a in A:
    DP=[[1<<60]*(1<<N) for i in range(N)]
    DP[a][1<<a]=0

    Q=[(0,a,1<<a)]

    while Q:
        time,now,b=heappop(Q)
        if DP[now][b]!=time:
            continue

        if b.bit_count()>=M:
            ANS=min(ANS,time)
            continue

        for i in range(N):
            if b & (1<<i) != 0:
                continue
            nb=b|(1<<i)

            if DP[i][nb]>time+T[i][now]:
                DP[i][nb]=time+T[i][now]
                heappush(Q,(DP[i][nb],i,nb))

print(ANS)
                
                
    
0