結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2020-11-19 16:44:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 852 bytes |
コンパイル時間 | 127 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 18,592 KB |
最終ジャッジ日時 | 2024-07-23 10:06:36 |
合計ジャッジ時間 | 6,773 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 TLE * 1 -- * 29 |
ソースコード
from collections import dequeN = int(input())queue = deque([{"count":1, "position":1}])passed_position = []result = -1while queue:q = queue.popleft()current_position = q["position"]current_count = q["count"]if current_position == N:result = current_countbreakif current_position < N:passed_position.append(current_position)steps = bin(current_position).count("1")forward_step = current_position + stepsbackward_step = current_position - stepsif forward_step not in passed_position and 1 < forward_step <= N:queue.append({"count":current_count+1, "position":forward_step})if backward_step not in passed_position and 1 < backward_step <= N:queue.append({"count":current_count+1, "position":backward_step})print(result)