結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
papinnie
|
| 提出日時 | 2019-09-19 17:47:44 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 549 ms / 5,000 ms |
| コード長 | 617 bytes |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 44,344 KB |
| 最終ジャッジ日時 | 2024-07-01 09:31:14 |
| 合計ジャッジ時間 | 21,012 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
import numpy as np
N = int(input())
moves = [bin(x).count('1') for x in range(N+1)]
routes = []
reachables = np.zeros(N+1, dtype=bool)
q = deque([(1,1)])
reachables[1] = True
while(q):
n, c = q.popleft()
if n == N:
routes.append(c)
break
else:
back, go = moves[n]* -1 + n, moves[n] + n
for target in [go, back]:
if (1 < target <= N) and not reachables[target]:
reachables[target] = True
q.append((target, c+1))
if len(routes) == 0:
print(-1) # unreachable
else:
print(min(routes))
papinnie