結果
問題 | No.1284 Flip Game |
ユーザー | titia |
提出日時 | 2020-11-06 22:59:10 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 974 bytes |
コンパイル時間 | 1,040 ms |
コンパイル使用メモリ | 86,760 KB |
実行使用メモリ | 135,264 KB |
最終ジャッジ日時 | 2023-09-29 19:26:43 |
合計ジャッジ時間 | 15,619 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
71,400 KB |
testcase_01 | AC | 76 ms
74,924 KB |
testcase_02 | AC | 225 ms
79,460 KB |
testcase_03 | AC | 71 ms
71,216 KB |
testcase_04 | AC | 72 ms
71,112 KB |
testcase_05 | AC | 71 ms
71,036 KB |
testcase_06 | AC | 72 ms
71,220 KB |
testcase_07 | AC | 75 ms
75,084 KB |
testcase_08 | AC | 74 ms
74,836 KB |
testcase_09 | AC | 85 ms
76,308 KB |
testcase_10 | AC | 80 ms
75,328 KB |
testcase_11 | AC | 126 ms
77,632 KB |
testcase_12 | AC | 134 ms
77,960 KB |
testcase_13 | AC | 194 ms
78,672 KB |
testcase_14 | AC | 206 ms
78,736 KB |
testcase_15 | AC | 465 ms
82,672 KB |
testcase_16 | AC | 491 ms
82,656 KB |
testcase_17 | AC | 313 ms
91,876 KB |
testcase_18 | AC | 309 ms
91,544 KB |
testcase_19 | AC | 908 ms
135,264 KB |
testcase_20 | AC | 1,806 ms
96,716 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 1,750 ms
96,396 KB |
testcase_23 | TLE | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
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])