結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-09 14:24:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 4,438 ms / 5,000 ms |
| コード長 | 788 bytes |
| コンパイル時間 | 163 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 20,024 KB |
| 最終ジャッジ日時 | 2024-07-01 07:16:33 |
| 合計ジャッジ時間 | 56,190 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#!/usr/bin/env python3
from collections import defaultdict
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 = sum([int(x) for x in list(format(node[0], "b"))])
nxts = [i + node[0] for i in [-r, r] if 0 < i + node[0] <= N]
return zip(nxts, [node[1] + 1] * len(nxts))
def print_route(route, node):
while node > 0:
print(node)
node = route[node]
N = int(input())
node = (1, 1, 0)
pend = []
went = []
route = {}
while node[0] < N:
went.append(node[0])
pend.extend([n for n in nexts(node) if n[0] not in went])
if len(pend) == 0:
print(-1)
exit()
node = pend.pop(0)
print(node[1])