結果

問題 No.3 ビットすごろく
ユーザー qibqib
提出日時 2023-02-25 00:09:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 415 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 77,564 KB
最終ジャッジ日時 2023-10-11 07:08:44
合計ジャッジ時間 6,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
70,840 KB
testcase_01 AC 95 ms
71,256 KB
testcase_02 AC 98 ms
71,212 KB
testcase_03 AC 117 ms
77,184 KB
testcase_04 AC 105 ms
76,848 KB
testcase_05 AC 116 ms
77,508 KB
testcase_06 AC 118 ms
77,036 KB
testcase_07 AC 113 ms
76,900 KB
testcase_08 AC 118 ms
76,956 KB
testcase_09 AC 121 ms
77,212 KB
testcase_10 AC 121 ms
77,208 KB
testcase_11 AC 118 ms
77,324 KB
testcase_12 AC 121 ms
77,324 KB
testcase_13 AC 114 ms
77,072 KB
testcase_14 AC 120 ms
77,552 KB
testcase_15 AC 123 ms
77,424 KB
testcase_16 AC 119 ms
77,184 KB
testcase_17 AC 121 ms
77,480 KB
testcase_18 AC 114 ms
77,048 KB
testcase_19 AC 122 ms
77,352 KB
testcase_20 AC 102 ms
76,072 KB
testcase_21 AC 94 ms
71,276 KB
testcase_22 AC 122 ms
76,972 KB
testcase_23 AC 125 ms
77,392 KB
testcase_24 AC 123 ms
77,564 KB
testcase_25 AC 125 ms
77,464 KB
testcase_26 AC 98 ms
71,320 KB
testcase_27 AC 117 ms
77,248 KB
testcase_28 AC 122 ms
77,328 KB
testcase_29 AC 123 ms
77,216 KB
testcase_30 AC 97 ms
71,200 KB
testcase_31 AC 100 ms
75,744 KB
testcase_32 AC 122 ms
77,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
dp = [None for _ in range(n + 1)]
dq = deque()

src = 1
dp[src] = 0
dq.append(src)
while len(dq) > 0:
  cur = dq.popleft()
  cnt = len([c for c in bin(cur) if c == '1'])
  for dir in [-1, 1]:
    nxt = cur + dir * cnt
    if 1 <= nxt <= n and dp[nxt] is None:
      dp[nxt] = dp[cur] + 1
      dq.append(nxt)

if dp[n] is None:
  print("-1")
else:
  print(dp[-1] + 1)
0