結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2019-05-28 15:54:43 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 212 ms / 5,000 ms |
コード長 | 1,117 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-07-01 09:20:58 |
合計ジャッジ時間 | 4,681 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
import sys sys.setrecursionlimit(10000) goal = int(input()) stepped = dict() maybe_answer = -1 def step(position, count): global maybe_answer # 現在地点が範囲外 if position not in range(1, goal + 1): return # 既に到達した位置か? if position in stepped: if count < stepped[position]: # 既出の到達経路より短い場合は、到達経路を更新 stepped[position] = count else: # 既出の到達経路と同じ、または大きい場合は処理終了 return else: stepped[position] = count # 既出のゴールまでの最短経路を超えてしまった if maybe_answer != -1 and count > maybe_answer: return # ゴールに到達したので処理終了 if position == goal: maybe_answer = count return # 現在位置から進む・戻るを検証 position_1bit_num = bin(position).count('1') step(position + position_1bit_num, count + 1) step(position - position_1bit_num, count + 1) step(1, 1) print(maybe_answer)