結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-02 20:46:00 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 511 bytes |
| コンパイル時間 | 529 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 259,840 KB |
| 最終ジャッジ日時 | 2024-11-15 16:15:05 |
| 合計ジャッジ時間 | 170,685 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 1 TLE * 28 |
ソースコード
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')