結果

問題 No.3158 Collect Stamps
コンテスト
ユーザー tkykwtnb
提出日時 2025-05-23 20:08:50
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 786 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 89 ms
コンパイル使用メモリ 64,400 KB
実行使用メモリ 1,296,096 KB
最終ジャッジ日時 2026-10-29 13:34:45
合計ジャッジ時間 12,416 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
N,M,K=map(int,input().split())
A=set(map(lambda x:int(x)-1,input().split()))
T=[list(map(int,input().split())) for _ in range(N)]
G=[[] for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if i==j:continue
        G[i].append(j)
        G[j].append(i)
ans=1<<60
for s in range(N):
    vis=[0 for _ in range(N)]
    Q=deque([(s,0,0,tuple(vis))])
    while Q:
        now,cnt,t,vis=Q.popleft()
        vis=list(vis)
        if vis[now]==0:
            cnt+=1
        vis[now]=1
        if cnt>=M and now in A:
            ans=min(ans,t)
            continue
        for nxt in G[now]:
            if cnt<M and vis[nxt]:continue
            if t+T[now][nxt]>ans:continue
            Q.append((nxt,cnt,t+T[now][nxt],tuple(vis)))
print(ans)
0