結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-02 20:47:38 |
| 言語 | Python3 (3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 566 bytes |
| 記録 | |
| コンパイル時間 | 55 ms |
| コンパイル使用メモリ | 14,976 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2026-09-23 08:26:52 |
| 合計ジャッジ時間 | 2,785 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 1 |
ソースコード
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()
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')