結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-19 17:08:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 925 bytes |
| コンパイル時間 | 143 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-07-23 10:08:24 |
| 合計ジャッジ時間 | 2,170 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 4 RE * 15 |
ソースコード
# 再帰呼び出し
N = int(input())
queue = {"count":1, "position":1}
passed_position = {1}
def get_count(q):
current_position = q["position"]
current_count = q["count"]
if current_position == N:
return current_count
elif current_position < N:
steps = bin(current_position).count("1")
forward_position = current_position + steps
backward_position = current_position - steps
if forward_position not in passed_position and 1 < forward_position <= N:
passed_position.add(forward_position)
return get_count({"count":current_count+1, "position":forward_position})
if backward_position not in passed_position and 1 < backward_position <= N:
passed_position.add(backward_position)
return get_count({"count":current_count+1, "position":backward_position})
result = get_count(queue)
print(result if result else -1)