結果

問題 No.1284 Flip Game
ユーザー titiatitia
提出日時 2020-11-06 23:24:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,035 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 84,536 KB
最終ジャッジ日時 2023-09-29 19:40:15
合計ジャッジ時間 12,829 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,320 KB
testcase_01 AC 75 ms
70,944 KB
testcase_02 AC 152 ms
77,580 KB
testcase_03 AC 76 ms
71,328 KB
testcase_04 AC 74 ms
71,264 KB
testcase_05 AC 72 ms
71,420 KB
testcase_06 AC 71 ms
71,108 KB
testcase_07 AC 75 ms
71,332 KB
testcase_08 AC 74 ms
71,260 KB
testcase_09 AC 92 ms
75,820 KB
testcase_10 AC 90 ms
76,164 KB
testcase_11 AC 129 ms
77,808 KB
testcase_12 AC 137 ms
77,992 KB
testcase_13 AC 154 ms
77,788 KB
testcase_14 AC 163 ms
78,108 KB
testcase_15 AC 264 ms
78,316 KB
testcase_16 AC 282 ms
78,684 KB
testcase_17 AC 199 ms
78,384 KB
testcase_18 AC 198 ms
77,784 KB
testcase_19 AC 387 ms
79,276 KB
testcase_20 AC 736 ms
78,572 KB
testcase_21 AC 958 ms
79,388 KB
testcase_22 AC 720 ms
78,352 KB
testcase_23 TLE -
testcase_24 TLE -
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)]

ANS=[1<<60]
DP=[[1<<60]*(3**N) for i in range(N)]

def shuku(A):
    k=0
    for i in range(N):
        k+=A[i]*(3**i)
    return k

def modos(x):
    S=[0]*N
    for i in range(N):
        S[i]=(x%(3**(i+1)))//(3**i)
    return S
        

def calc(xx,f):
    A=modos(xx)

    if sum(A)==2*N:
        ANS[0]=min(ANS[0],DP[f][xx])
        return
    if sum(A)==2*N-1:
        x=A.index(1)
        if x==f:
            ANS[0]=min(ANS[0],DP[f][xx])
            return
            
    for i in range(N):
        if i==f:
            continue
        if A[i]==2:
            continue

        A[i]+=1
        if DP[i][shuku(A)]>DP[f][xx]+C[f][i]:
            DP[i][shuku(A)]=DP[f][xx]+C[f][i]
            Q.append((i,shuku(A)))
        A[i]-=1

A=[0]*N
Q=[]
for i in range(N):
    A[i]+=1
    DP[i][shuku(A)]=0
    Q.append((i,shuku(A)))
    A[i]-=1

while Q:
    f,x=Q.pop()
    calc(x,f)
    

print(ANS[0])


    
            
0