結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-19 16:53:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 5,000 ms |
| コード長 | 542 bytes |
| コンパイル時間 | 270 ms |
| コンパイル使用メモリ | 82,600 KB |
| 実行使用メモリ | 74,520 KB |
| 最終ジャッジ日時 | 2024-06-22 22:10:16 |
| 合計ジャッジ時間 | 3,254 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
inpl = lambda: list(map(int,input().split()))
N = int(input())
visited = [False]*N
q = deque([-1,0])
ans = 0
while q:
x = q.popleft()
if x == N-1:
print(ans)
exit()
elif x < 0:
ans += 1
if q:
q.append(-1)
elif not visited[x]:
visited[x] = True
w = bin(x+1).count('1')
for y in [x-w, x+w]:
if y < 0 or y > N-1:
continue
elif not visited[y]:
q.append(y)
else:
print(-1)