結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-09 14:39:11 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 111 ms / 5,000 ms |
| コード長 | 641 bytes |
| 記録 | |
| コンパイル時間 | 589 ms |
| コンパイル使用メモリ | 20,572 KB |
| 実行使用メモリ | 16,888 KB |
| 最終ジャッジ日時 | 2026-03-22 03:06:58 |
| 合計ジャッジ時間 | 4,827 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#!/usr/bin/env python3
from collections import deque
def memoize(f):
table = {}
def func(*args):
if not args in table:
table[args] = f(*args)
return table[args]
return func
@memoize
def nexts(node):
r = format(node, "b").count('1')
return [i + node for i in (-r, r) if 0 < i + node <= N]
N = int(input())
node = 1
pend = deque()
hop = {1: 1}
while node < N:
nxts = [n for n in nexts(node) if n not in hop.keys()]
pend.extend(nxts)
for n in nxts:
hop[n] = hop[node] + 1
if len(pend) == 0:
print(-1)
exit()
node = pend.popleft()
print(hop[N])