結果

問題 No.1284 Flip Game
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-19 08:52:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 1,159 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 98,116 KB
最終ジャッジ日時 2023-10-13 17:18:26
合計ジャッジ時間 7,594 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,304 KB
testcase_01 AC 63 ms
71,496 KB
testcase_02 AC 121 ms
78,516 KB
testcase_03 AC 63 ms
71,548 KB
testcase_04 AC 64 ms
71,256 KB
testcase_05 AC 63 ms
71,532 KB
testcase_06 AC 68 ms
71,596 KB
testcase_07 AC 67 ms
71,312 KB
testcase_08 AC 67 ms
71,288 KB
testcase_09 AC 68 ms
71,336 KB
testcase_10 AC 67 ms
71,124 KB
testcase_11 AC 82 ms
76,692 KB
testcase_12 AC 84 ms
76,712 KB
testcase_13 AC 101 ms
78,256 KB
testcase_14 AC 100 ms
78,512 KB
testcase_15 AC 130 ms
79,860 KB
testcase_16 AC 131 ms
79,980 KB
testcase_17 AC 170 ms
83,992 KB
testcase_18 AC 174 ms
83,936 KB
testcase_19 AC 295 ms
98,088 KB
testcase_20 AC 185 ms
83,920 KB
testcase_21 AC 185 ms
83,756 KB
testcase_22 AC 185 ms
83,660 KB
testcase_23 AC 343 ms
97,768 KB
testcase_24 AC 302 ms
98,116 KB
testcase_25 AC 302 ms
97,596 KB
testcase_26 AC 300 ms
98,036 KB
testcase_27 AC 307 ms
98,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
n=int(input())
c=[list(map(int,input().split())) for _ in range(n)]

inf=float('inf')
memo={}
memo[0]=0
d={}
for i in range(n):
  d[2**i+2**(i+n)]=i
def func(red,pre):
  key=(red,pre)
  if red==0:memo[key]=0
  if red in d:
    i=d[red]
    return c[pre][i]
  if key in memo:return memo[key]
  ret=inf
  for i in range(n):
    if i==pre:continue
    if (red>>i)&1:
      ret=min(ret,func(red^(1<<i),i)+c[pre][i])
    elif (red>>(n+i))&1:
      ret=min(ret,func(red^(1<<(n+i)),i)+c[pre][i])
  memo[key]=ret
  return ret
c.append([0]*n)
ret=func(2**(2*n)-1,-1)
print(ret)
0