結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2024-06-09 17:46:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 73 ms / 5,000 ms |
コード長 | 487 bytes |
コンパイル時間 | 443 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 64,512 KB |
最終ジャッジ日時 | 2024-12-30 13:51:17 |
合計ジャッジ時間 | 3,763 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from collections import deque N = int(input()) dist = [0] * (N + 1) visited = [False] * (N + 1) q = deque() q.append(1) visited[1] = True while q: x = q.popleft() p = x.bit_count() if x + p <= N and not visited[x + p]: visited[x + p] = True dist[x + p] = dist[x] + 1 q.append(x + p) if x - p > 0 and not visited[x - p]: visited[x - p] = True dist[x - p] = dist[x] + 1 q.append(x - p) print(dist[N]+1 if visited[N] else -1)