結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2024-07-02 21:57:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 5,000 ms |
| コード長 | 363 bytes |
| コンパイル時間 | 775 ms |
| コンパイル使用メモリ | 82,032 KB |
| 実行使用メモリ | 64,352 KB |
| 最終ジャッジ日時 | 2024-07-02 21:57:06 |
| 合計ジャッジ時間 | 2,662 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
N = int(input())
dists = [-1] * (N+1)
dists[1] = 1
q = deque([1])
while q:
x = q.popleft()
d = x.bit_count()
l = x-d
if l > 0 and dists[l] == -1:
dists[l] = dists[x] + 1
q.append(l)
r = x+d
if r <= N and dists[r] == -1:
dists[r] = dists[x] + 1
q.append(r)
print(dists[N])
norioc