結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-19 16:53:45 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 5,000 ms |
| コード長 | 542 bytes |
| 記録 | |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 85,512 KB |
| 実行使用メモリ | 75,292 KB |
| 最終ジャッジ日時 | 2026-03-07 04:34:51 |
| 合計ジャッジ時間 | 2,569 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)