結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2020-11-19 16:44:08 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 863 bytes |
コンパイル時間 | 123 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 18,336 KB |
最終ジャッジ日時 | 2024-07-23 10:05:41 |
合計ジャッジ時間 | 12,675 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 32 |
ソースコード
from collections import deque# N = int(input())N = 2343queue = 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)