結果

問題 No.1284 Flip Game
ユーザー ああいいああいい
提出日時 2022-02-19 14:46:38
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,065 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 301,948 KB
最終ジャッジ日時 2023-09-11 20:39:47
合計ジャッジ時間 9,013 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
75,768 KB
testcase_01 AC 79 ms
71,504 KB
testcase_02 AC 210 ms
81,152 KB
testcase_03 AC 77 ms
71,308 KB
testcase_04 AC 77 ms
71,396 KB
testcase_05 AC 77 ms
71,388 KB
testcase_06 AC 77 ms
71,084 KB
testcase_07 AC 77 ms
71,404 KB
testcase_08 AC 79 ms
71,520 KB
testcase_09 AC 93 ms
76,968 KB
testcase_10 AC 96 ms
76,880 KB
testcase_11 AC 151 ms
78,692 KB
testcase_12 AC 150 ms
79,140 KB
testcase_13 AC 208 ms
80,272 KB
testcase_14 AC 213 ms
81,364 KB
testcase_15 AC 350 ms
91,388 KB
testcase_16 AC 345 ms
93,224 KB
testcase_17 AC 684 ms
155,944 KB
testcase_18 AC 676 ms
156,004 KB
testcase_19 TLE -
testcase_20 AC 1,103 ms
170,000 KB
testcase_21 AC 1,155 ms
170,688 KB
testcase_22 AC 1,145 ms
170,220 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

inf = 10 ** 11
ans = 10 ** 11
import heapq
for i in range(N):
    dp = [[[inf] * N for _ in range(1 << N)] for _ in range(1 << N)]
    dp[1 << i][0][i] = 0
    q = [(0,1 << i,0,i)]
    while q:
        d,S,T,last = heapq.heappop(q)
        maskl = 1 << last
        for j in range(N):
            maskj = 1 << j
            if S & maskj:continue
            if T & maskl:
                if dp[S | maskj][T][j] > d + c[last][j]:
                    dp[S | maskj][T][j] = d + c[last][j]
                    heapq.heappush(q,(d + c[last][j],S|maskj,T,j))
            else:
                bit =(S | maskj) ^ maskl
                if dp[bit][T | maskl][j] > d + c[last][j]:
                    dp[bit][T | maskl][j] = d + c[last][j]
                    heapq.heappush(q,(d + c[last][j],bit,T | maskl,j))
    _min = inf
    for T in range(1 << N):
        for j in range(N):
            if dp[-1][T][j] < _min:
                _min = dp[-1][T][j]
    if _min < ans:
        ans = _min
print(ans)
0