結果

問題 No.3 ビットすごろく
ユーザー ic-eguciic-eguci
提出日時 2019-01-31 15:18:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 920 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 76,452 KB
最終ジャッジ日時 2024-04-27 15:32:54
合計ジャッジ時間 9,551 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,880 KB
testcase_01 AC 34 ms
10,880 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 458 ms
16,000 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 2,097 ms
34,944 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

bitcount = {2:1, 6:2, 14:3, 30:4, 62:5, 126:6, 254:7, 510:8, 1022:9, 2046:10, 4094:11, 8190:12, 16382:13, }
def get_max_bitcount(n):
    for i in bitcount:
        if n <= i:
            return bitcount[i]


def foo(N):

    def get_reachable(st):
        reachable = set([])
        for l in st:
            for i in range(1, get_max_bitcount(l)+2):
                if i == bin(l-i).count('1'):
                    if (l-i) >= 1:
                        reachable.add(l-i)
                if i == bin(l+i).count('1'):
                    if (l+i) <= N:
                        reachable.add(l+i)
        return reachable

    def bar(st):
        nonlocal count
        count += 1
        if not st:
            return -1
        if 1 in st:
            return count
        return bar(get_reachable(st))

    if N == 1:
        return 1

    count = 1
    return bar(get_reachable(set([N])))


print(foo(int(input())))
0