結果

問題 No.3 ビットすごろく
ユーザー warashiwarashi
提出日時 2015-02-09 14:27:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 906 ms / 5,000 ms
コード長 725 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 13,000 KB
最終ジャッジ日時 2023-09-13 23:01:50
合計ジャッジ時間 13,126 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,544 KB
testcase_01 AC 18 ms
8,452 KB
testcase_02 AC 18 ms
8,488 KB
testcase_03 AC 81 ms
9,640 KB
testcase_04 AC 27 ms
8,724 KB
testcase_05 AC 283 ms
10,780 KB
testcase_06 AC 94 ms
9,616 KB
testcase_07 AC 47 ms
9,100 KB
testcase_08 AC 193 ms
10,388 KB
testcase_09 AC 451 ms
11,456 KB
testcase_10 AC 627 ms
12,004 KB
testcase_11 AC 382 ms
11,188 KB
testcase_12 AC 269 ms
10,692 KB
testcase_13 AC 66 ms
9,520 KB
testcase_14 AC 589 ms
12,116 KB
testcase_15 AC 884 ms
12,800 KB
testcase_16 AC 771 ms
12,536 KB
testcase_17 AC 859 ms
12,792 KB
testcase_18 AC 54 ms
9,292 KB
testcase_19 AC 900 ms
12,852 KB
testcase_20 AC 23 ms
8,624 KB
testcase_21 AC 18 ms
8,484 KB
testcase_22 AC 605 ms
12,008 KB
testcase_23 AC 906 ms
12,876 KB
testcase_24 AC 906 ms
12,984 KB
testcase_25 AC 881 ms
13,000 KB
testcase_26 AC 18 ms
8,484 KB
testcase_27 AC 73 ms
9,540 KB
testcase_28 AC 744 ms
12,720 KB
testcase_29 AC 395 ms
11,204 KB
testcase_30 AC 19 ms
8,640 KB
testcase_31 AC 20 ms
8,532 KB
testcase_32 AC 342 ms
10,984 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))


N = int(input())
node = (1, 1, 0)
pend = []
pended = []
route = {}
while node[0] < N:
    nxts = [n for n in nexts(node) if n[0] not in pended]
    pend.extend(nxts)
    pended.extend([n[0] for n in nxts])
    if len(pend) == 0:
        print(-1)
        exit()
    node = pend.pop(0)

print(node[1])
0