結果

問題 No.1284 Flip Game
ユーザー rlangevinrlangevin
提出日時 2023-02-05 23:26:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 533 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 86,556 KB
実行使用メモリ 116,064 KB
最終ジャッジ日時 2023-09-17 13:09:37
合計ジャッジ時間 7,601 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
70,876 KB
testcase_01 AC 77 ms
71,144 KB
testcase_02 AC 112 ms
77,788 KB
testcase_03 AC 80 ms
71,036 KB
testcase_04 AC 77 ms
71,176 KB
testcase_05 AC 77 ms
70,892 KB
testcase_06 AC 77 ms
71,156 KB
testcase_07 AC 77 ms
70,872 KB
testcase_08 AC 76 ms
71,052 KB
testcase_09 AC 82 ms
75,472 KB
testcase_10 AC 82 ms
75,608 KB
testcase_11 AC 96 ms
76,280 KB
testcase_12 AC 97 ms
76,360 KB
testcase_13 AC 104 ms
76,592 KB
testcase_14 AC 106 ms
76,460 KB
testcase_15 AC 120 ms
79,096 KB
testcase_16 AC 118 ms
79,308 KB
testcase_17 AC 183 ms
86,332 KB
testcase_18 AC 181 ms
86,424 KB
testcase_19 AC 476 ms
115,888 KB
testcase_20 AC 193 ms
86,456 KB
testcase_21 AC 189 ms
86,520 KB
testcase_22 AC 194 ms
86,496 KB
testcase_23 AC 479 ms
115,772 KB
testcase_24 AC 533 ms
116,064 KB
testcase_25 AC 490 ms
115,916 KB
testcase_26 AC 477 ms
115,988 KB
testcase_27 AC 523 ms
115,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
C = []
for i in range(N):
    C.append(list(map(int, input().split())))
    
inf = 10 ** 18
N2 = 1 << (2 * N)
dp = [[inf] * N for i in range(N2)]
for i in range(N):
    dp[1 << i][i] = 0
    
for s in range(1, N2):
    for p in range(N):
        if (s >> p) & 1 == 0:
            continue
        for q in range(N):
            if p == q:
                continue
            if (s >> q) & 1 and (s >> (q + N)) & 1:
                continue
            # if (s >> (p + N)) & 1:
            #     ns = s ^ (1 << (p + N))
            # else:
            #     ns = s ^ (1 << p)
            if (s >> q) & 1 == 0:
                ns = s | (1 << q)
                dp[ns][q] = min(dp[ns][q], dp[s][p] + C[p][q])
            else:
                ns = s | (1 << (q + N))
                dp[ns][q] = min(dp[ns][q], dp[s][p] + C[p][q])
            
ans = min(dp[-1])
for i in range(N):
    ans = min(ans, dp[(N2 - 1)^(1 << (i + N))][i])
print(ans)
0