結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-02 20:48:30 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 5,000 ms |
| コード長 | 619 bytes |
| コンパイル時間 | 216 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,648 KB |
| 最終ジャッジ日時 | 2024-11-15 16:17:17 |
| 合計ジャッジ時間 | 2,546 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
def bitcount(x):
return bin(x).count('1')
n = int(input())
states = deque([(1, 1)])
searched = {1}
while len(states) > 0:
pos, turn = states.popleft()
if pos == n:
print(turn)
exit(0)
left = pos - bitcount(pos)
right = pos + bitcount(pos)
if left == n or right == n:
print(turn + 1)
exit(0)
if left not in searched and left > 0:
searched.add(left)
states.append((left, turn + 1))
if right not in searched and right < n:
searched.add(right)
states.append((right, turn + 1))
print('-1')