結果
問題 | No.1284 Flip Game |
ユーザー |
|
提出日時 | 2022-02-19 14:46:38 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,065 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 296,656 KB |
最終ジャッジ日時 | 2024-06-29 10:24:31 |
合計ジャッジ時間 | 13,665 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 TLE * 2 -- * 4 |
ソースコード
N = int(input())c = [list(map(int,input().split())) for _ in range(N)]inf = 10 ** 11ans = 10 ** 11import heapqfor i in range(N):dp = [[[inf] * N for _ in range(1 << N)] for _ in range(1 << N)]dp[1 << i][0][i] = 0q = [(0,1 << i,0,i)]while q:d,S,T,last = heapq.heappop(q)maskl = 1 << lastfor j in range(N):maskj = 1 << jif S & maskj:continueif T & maskl:if dp[S | maskj][T][j] > d + c[last][j]:dp[S | maskj][T][j] = d + c[last][j]heapq.heappush(q,(d + c[last][j],S|maskj,T,j))else:bit =(S | maskj) ^ masklif dp[bit][T | maskl][j] > d + c[last][j]:dp[bit][T | maskl][j] = d + c[last][j]heapq.heappush(q,(d + c[last][j],bit,T | maskl,j))_min = inffor T in range(1 << N):for j in range(N):if dp[-1][T][j] < _min:_min = dp[-1][T][j]if _min < ans:ans = _minprint(ans)