結果
| 問題 |
No.1284 Flip Game
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2020-11-06 23:00:15 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 974 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 36,372 KB |
| 最終ジャッジ日時 | 2024-07-22 13:31:40 |
| 合計ジャッジ時間 | 14,036 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 TLE * 4 -- * 4 |
ソースコード
import sys
input = sys.stdin.readline
N=int(input())
C=[list(map(int,input().split())) for i in range(N)]
DP=dict()
ANS=[1<<60]
def calc(A,f,c):
if (A,f) in DP and DP[A,f]<c:
return
if sum(A)==2*N:
ANS[0]=min(ANS[0],c)
return
if sum(A)==2*N-1:
x=A.index(1)
if x==f:
ANS[0]=min(ANS[0],c)
return
X=list(A)
for i in range(N):
if i==f:
continue
if X[i]==2:
continue
X[i]+=1
if (tuple(X),i) in DP:
if DP[tuple(X),i]>c+C[f][i]:
DP[tuple(X),i]=c+C[f][i]
Q.append((tuple(X),i,DP[tuple(X),i]))
else:
DP[tuple(X),i]=c+C[f][i]
Q.append((tuple(X),i,DP[tuple(X),i]))
X[i]-=1
A=[0]*N
Q=[]
for i in range(N):
A[i]+=1
Q.append((tuple(A),i,0))
A[i]-=1
while Q:
A,f,c=Q.pop()
calc(A,f,c)
print(ANS[0])
titia