結果

問題 No.3 ビットすごろく
ユーザー なえしら
提出日時 2023-11-19 19:17:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 269 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 62,592 KB
最終ジャッジ日時 2024-09-26 06:21:14
合計ジャッジ時間 4,001 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())

cnt = [-1]*(N+1)
cnt[1] = 1
que = deque([1])
while que:
  i = que.popleft()
  d = i.bit_count()
  for j in [i - d, i + d]:
    if 1 <= j <= N and cnt[j] == -1:
      cnt[j] = cnt[i] + 1
      que.append(j)

print(cnt[N])
0