結果

問題 No.1284 Flip Game
ユーザー mkawa2mkawa2
提出日時 2020-11-07 14:13:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 741 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 15,060 KB
最終ジャッジ日時 2023-09-29 20:34:16
合計ジャッジ時間 6,970 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,104 KB
testcase_01 AC 15 ms
8,168 KB
testcase_02 AC 28 ms
8,104 KB
testcase_03 AC 15 ms
8,092 KB
testcase_04 AC 15 ms
8,028 KB
testcase_05 AC 15 ms
8,008 KB
testcase_06 AC 15 ms
8,012 KB
testcase_07 AC 15 ms
8,060 KB
testcase_08 AC 15 ms
8,196 KB
testcase_09 AC 16 ms
8,028 KB
testcase_10 AC 16 ms
8,096 KB
testcase_11 AC 18 ms
8,104 KB
testcase_12 AC 18 ms
8,080 KB
testcase_13 AC 27 ms
8,108 KB
testcase_14 AC 27 ms
8,200 KB
testcase_15 AC 67 ms
8,840 KB
testcase_16 AC 64 ms
8,792 KB
testcase_17 AC 202 ms
9,184 KB
testcase_18 AC 206 ms
10,172 KB
testcase_19 AC 741 ms
11,252 KB
testcase_20 AC 198 ms
10,160 KB
testcase_21 AC 199 ms
10,144 KB
testcase_22 AC 194 ms
10,308 KB
testcase_23 AC 699 ms
14,840 KB
testcase_24 AC 706 ms
14,904 KB
testcase_25 AC 698 ms
14,896 KB
testcase_26 AC 720 ms
15,060 KB
testcase_27 AC 730 ms
14,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()

# 10進数aをdigitケタのn進数のリストに変換
def ton(a,n,digit):
    res=[0]*digit
    for i in range(digit):
        if a==0:break
        a,r=divmod(a,n)
        res[i]=r
    return res

inf=10**16
n=II()
cc=LLI(n)

dp=[[inf]*n for _ in range(3**n)]
bit=1
for i in range(n):
    dp[bit][i]=0
    bit*=3

def chmin(i,j,val):
    if val<dp[i][j]:dp[i][j]=val

for bit in range(3**n):
    for i in range(n):
        pre=dp[bit][i]
        if pre==inf:continue
        aa=ton(bit,3,n)
        for ni in range(n):
            if ni==i:continue
            if aa[ni]==2:continue
            chmin(bit+pow(3,ni),ni,pre+cc[i][ni])

goal=3**n-1
ans=min(min(dp[goal]),min(dp[goal-pow(3,i)][i] for i in range(n)))

# p2D(dp)
print(ans)
0