結果

問題 No.3 ビットすごろく
コンテスト
ユーザー 定期定期
提出日時 2024-11-11 02:21:38
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 51 ms / 5,000 ms
+ 228µs
コード長 598 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 57 ms
コンパイル使用メモリ 15,104 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2026-09-21 18:11:46
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(10**6)

n = int(input())
point_list = [-1 for _ in range(n+1)]
point_list[1] = 1
  
def move(point):
  left = point - point.bit_count()
  right = point + point.bit_count()
  if right < n + 1:
    if point_list[right] == -1 or point_list[right] > point_list[point] + 1:
      point_list[right] = point_list[point] + 1
      move(right)
  if left > 0:
    if point_list[left] == -1 or point_list[left] > point_list[point] + 1:
      point_list[left] = point_list[point] + 1
      move(left)

move(1)

if point_list[n] != -1 :
  print(point_list[n])
else :
  print(-1)
0