結果

問題 No.1284 Flip Game
ユーザー titiatitia
提出日時 2020-11-06 23:00:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 974 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,116 KB
実行使用メモリ 33,884 KB
最終ジャッジ日時 2023-09-29 19:26:59
合計ジャッジ時間 12,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,692 KB
testcase_01 AC 16 ms
8,192 KB
testcase_02 AC 82 ms
9,064 KB
testcase_03 AC 16 ms
8,236 KB
testcase_04 AC 16 ms
8,296 KB
testcase_05 AC 16 ms
8,168 KB
testcase_06 AC 16 ms
8,172 KB
testcase_07 AC 16 ms
8,192 KB
testcase_08 AC 16 ms
8,400 KB
testcase_09 AC 18 ms
8,272 KB
testcase_10 AC 17 ms
8,260 KB
testcase_11 AC 24 ms
8,356 KB
testcase_12 AC 27 ms
8,496 KB
testcase_13 AC 73 ms
9,056 KB
testcase_14 AC 90 ms
9,016 KB
testcase_15 AC 376 ms
10,504 KB
testcase_16 AC 414 ms
10,472 KB
testcase_17 AC 219 ms
15,704 KB
testcase_18 AC 224 ms
16,920 KB
testcase_19 AC 807 ms
33,884 KB
testcase_20 AC 1,834 ms
16,812 KB
testcase_21 TLE -
testcase_22 AC 1,715 ms
16,748 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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])


    
            
0