結果

問題 No.3 ビットすごろく
ユーザー popketlepopketle
提出日時 2019-12-19 05:30:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 375 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 9,300 KB
最終ジャッジ日時 2023-09-14 01:33:39
合計ジャッジ時間 2,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
8,984 KB
testcase_01 AC 24 ms
8,936 KB
testcase_02 AC 23 ms
9,072 KB
testcase_03 AC 36 ms
8,948 KB
testcase_04 AC 27 ms
8,936 KB
testcase_05 AC 49 ms
9,204 KB
testcase_06 AC 36 ms
8,932 KB
testcase_07 AC 30 ms
9,028 KB
testcase_08 AC 43 ms
8,984 KB
testcase_09 AC 56 ms
9,196 KB
testcase_10 AC 62 ms
9,220 KB
testcase_11 AC 53 ms
9,180 KB
testcase_12 AC 48 ms
9,136 KB
testcase_13 AC 33 ms
9,084 KB
testcase_14 AC 62 ms
9,160 KB
testcase_15 AC 71 ms
9,240 KB
testcase_16 AC 67 ms
9,200 KB
testcase_17 AC 69 ms
9,248 KB
testcase_18 AC 32 ms
9,020 KB
testcase_19 AC 71 ms
9,300 KB
testcase_20 AC 26 ms
8,944 KB
testcase_21 AC 23 ms
8,884 KB
testcase_22 AC 62 ms
9,224 KB
testcase_23 AC 71 ms
9,244 KB
testcase_24 AC 71 ms
9,228 KB
testcase_25 AC 70 ms
9,164 KB
testcase_26 AC 24 ms
9,060 KB
testcase_27 AC 34 ms
8,968 KB
testcase_28 AC 65 ms
9,244 KB
testcase_29 AC 54 ms
9,120 KB
testcase_30 AC 24 ms
9,008 KB
testcase_31 AC 25 ms
8,936 KB
testcase_32 AC 52 ms
9,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from queue import Queue
n=int(input())

memo=[float('inf')]*n
def bfs(q):
  x,cnt=q.get()
  if x<1 or x>n:
    return
  else:
    if memo[x-1]>cnt:
      memo[x-1]=cnt
      dst=str(bin(x))[2:].count('1')
      q.put([x-dst,cnt+1])
      q.put([x+dst,cnt+1])
      
q=Queue()
q.put([1,1])
while not q.empty():
  bfs(q)
print(-1) if memo[-1]==float('inf') else print(memo[-1])
0