結果

問題 No.1284 Flip Game
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-11-07 01:59:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 80,704 KB
最終ジャッジ日時 2023-09-29 19:59:25
合計ジャッジ時間 4,406 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,428 KB
testcase_01 AC 71 ms
70,960 KB
testcase_02 AC 92 ms
76,312 KB
testcase_03 AC 72 ms
71,424 KB
testcase_04 AC 72 ms
71,132 KB
testcase_05 AC 71 ms
71,492 KB
testcase_06 AC 71 ms
71,128 KB
testcase_07 AC 72 ms
71,256 KB
testcase_08 AC 72 ms
71,304 KB
testcase_09 AC 73 ms
71,056 KB
testcase_10 AC 73 ms
71,272 KB
testcase_11 AC 86 ms
76,592 KB
testcase_12 AC 86 ms
76,436 KB
testcase_13 AC 91 ms
76,532 KB
testcase_14 AC 93 ms
76,300 KB
testcase_15 AC 99 ms
76,412 KB
testcase_16 AC 101 ms
76,852 KB
testcase_17 AC 111 ms
76,632 KB
testcase_18 AC 109 ms
76,412 KB
testcase_19 AC 155 ms
80,588 KB
testcase_20 AC 108 ms
76,668 KB
testcase_21 AC 109 ms
76,544 KB
testcase_22 AC 110 ms
76,844 KB
testcase_23 AC 153 ms
80,704 KB
testcase_24 AC 155 ms
80,444 KB
testcase_25 AC 155 ms
80,212 KB
testcase_26 AC 152 ms
80,524 KB
testcase_27 AC 154 ms
80,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))

def dist(u,v):
    return X[u][v]


dp = [[10**18]*N for _ in range(3**N)]
for v in range(N):
    dp[3**v][v] = 0
for b in range(1, 3**N):
    for v in range(N):
        vb = (b//(3**v))%3
        if not vb: 
            continue
        for u in range(N):
            ub = (b//(3**u))%3
            if not ub:
                continue
            if u==v:
                if b+1 == 3**N and vb == 2:
                    dp[b][v] = min(dp[b][v], dp[b-3**v][u] + dist(u, v))
                continue
            dp[b][v] = min(dp[b][v], dp[b-3**v][u] + dist(u, v))


print(min(dp[3**N-1]))
0