結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-26 11:56:19 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 5,000 ms |
| コード長 | 574 bytes |
| コンパイル時間 | 249 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-11-18 08:53:39 |
| 合計ジャッジ時間 | 2,162 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
def read_int(): return int(input())
def read_int_list(): return list(map(int, input().split()))
N = read_int()
costs = [10000000] * (N + 1)
used = [False] * (N + 1)
costs[1] = 1
q = deque()
q.append(1)
while q:
v = q.popleft()
if used[v]:
continue
used[v] = True
bits = bin(v).count('1')
g = [v - bits, v + bits]
for i in g:
if i > N:
continue
if costs[i] > costs[v] + 1:
costs[i] = costs[v] + 1
q.append(i)
print(-1 if costs[N] == 10000000 else costs[N])