結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
tnodino
|
| 提出日時 | 2022-05-26 18:08:21 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 170 ms / 5,000 ms |
| コード長 | 556 bytes |
| 記録 | |
| コンパイル時間 | 750 ms |
| コンパイル使用メモリ | 20,704 KB |
| 実行使用メモリ | 15,360 KB |
| 最終ジャッジ日時 | 2026-04-09 01:26:47 |
| 合計ジャッジ時間 | 6,383 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
def bfs():
INF = 1<<32
cost = [INF] * (N+1)
cost[1] = 1
Queue = deque()
Queue.append(1)
while Queue:
x = Queue.popleft()
C = bin(x).count('1')
if 1 <= x - C and cost[x] + 1 < cost[x-C]:
cost[x-C] = cost[x] + 1
Queue.append(x-C)
if x + C <= N and cost[x] + 1 < cost[x+C]:
cost[x+C] = cost[x] + 1
Queue.append(x+C)
return cost
INF = 1<<32
N = int(input())
cost = bfs()
if cost[N] == INF:
cost[N] = -1
print(cost[N])
tnodino