結果

問題 No.3 ビットすごろく
ユーザー warashiwarashi
提出日時 2015-02-09 14:24:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,859 ms / 5,000 ms
コード長 788 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 10,756 KB
実行使用メモリ 17,508 KB
最終ジャッジ日時 2023-09-13 23:05:00
合計ジャッジ時間 48,286 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,492 KB
testcase_01 AC 18 ms
8,624 KB
testcase_02 AC 17 ms
8,620 KB
testcase_03 AC 251 ms
10,784 KB
testcase_04 AC 46 ms
9,032 KB
testcase_05 AC 1,084 ms
13,188 KB
testcase_06 AC 309 ms
10,912 KB
testcase_07 AC 121 ms
9,800 KB
testcase_08 AC 690 ms
12,324 KB
testcase_09 AC 1,768 ms
14,560 KB
testcase_10 AC 2,553 ms
16,248 KB
testcase_11 AC 1,488 ms
14,004 KB
testcase_12 AC 1,024 ms
13,080 KB
testcase_13 AC 184 ms
10,212 KB
testcase_14 AC 2,406 ms
15,908 KB
testcase_15 AC 3,619 ms
17,488 KB
testcase_16 AC 3,243 ms
16,884 KB
testcase_17 AC 3,650 ms
17,168 KB
testcase_18 AC 148 ms
10,096 KB
testcase_19 AC 3,859 ms
17,360 KB
testcase_20 AC 35 ms
8,936 KB
testcase_21 AC 19 ms
8,620 KB
testcase_22 AC 2,523 ms
15,848 KB
testcase_23 AC 3,844 ms
17,508 KB
testcase_24 AC 3,818 ms
17,456 KB
testcase_25 AC 3,735 ms
17,404 KB
testcase_26 AC 18 ms
8,532 KB
testcase_27 AC 225 ms
10,428 KB
testcase_28 AC 3,062 ms
16,640 KB
testcase_29 AC 1,550 ms
14,264 KB
testcase_30 AC 20 ms
8,624 KB
testcase_31 AC 21 ms
8,724 KB
testcase_32 AC 1,335 ms
13,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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])
0