結果

問題 No.1284 Flip Game
ユーザー ああいいああいい
提出日時 2022-02-19 14:51:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,298 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 287,588 KB
最終ジャッジ日時 2023-09-11 20:40:04
合計ジャッジ時間 17,048 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
75,848 KB
testcase_01 AC 79 ms
71,128 KB
testcase_02 AC 199 ms
81,100 KB
testcase_03 AC 80 ms
71,364 KB
testcase_04 AC 80 ms
71,132 KB
testcase_05 AC 82 ms
71,468 KB
testcase_06 AC 81 ms
71,352 KB
testcase_07 AC 81 ms
71,368 KB
testcase_08 AC 81 ms
71,464 KB
testcase_09 AC 85 ms
71,464 KB
testcase_10 AC 84 ms
71,304 KB
testcase_11 AC 147 ms
78,556 KB
testcase_12 AC 148 ms
78,396 KB
testcase_13 AC 203 ms
81,120 KB
testcase_14 AC 206 ms
81,236 KB
testcase_15 AC 269 ms
87,824 KB
testcase_16 AC 235 ms
85,320 KB
testcase_17 AC 520 ms
151,112 KB
testcase_18 AC 513 ms
151,460 KB
testcase_19 AC 1,638 ms
273,636 KB
testcase_20 AC 621 ms
154,540 KB
testcase_21 AC 459 ms
153,328 KB
testcase_22 AC 580 ms
153,404 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
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
def pack(S,T,j):
    return (S << 13) + (T << 4) + j
def unpack(z):
    S = z >> 13
    z %= (1 << 13)
    T = z >> 4
    j = z % (1 << 4)
    return (S,T,j)
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,pack(1 << i,0,i))]
    while q:
        d,z = heapq.heappop(q)
        S,T,last = unpack(z)
        if S == (1 << N) - 1:break
        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],pack(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],pack(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