結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-02 20:46:00 |
| 言語 | Python3 (3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL) |
| 結果 |
MLE
不安定
|
| 実行時間 | - |
| コード長 | 511 bytes |
| 記録 | |
| コンパイル時間 | 345 ms |
| コンパイル使用メモリ | 15,104 KB |
| 実行使用メモリ | 576,768 KB |
| 最終ジャッジ日時 | 2026-09-23 08:24:28 |
| 合計ジャッジ時間 | 10,300 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 MLE * 1 -- * 29 |
ソースコード
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:
states.append((left, turn + 1))
if right not in searched and right < n:
states.append((right, turn + 1))
print('-1')