結果

問題 No.3 ビットすごろく
ユーザー nanaenanae
提出日時 2017-02-22 19:25:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 651 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 9,152 KB
最終ジャッジ日時 2023-09-14 00:20:38
合計ジャッジ時間 2,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,448 KB
testcase_01 AC 17 ms
8,596 KB
testcase_02 AC 17 ms
8,584 KB
testcase_03 AC 22 ms
8,612 KB
testcase_04 AC 20 ms
8,612 KB
testcase_05 AC 27 ms
8,808 KB
testcase_06 AC 22 ms
8,792 KB
testcase_07 AC 20 ms
8,632 KB
testcase_08 AC 25 ms
8,708 KB
testcase_09 AC 28 ms
8,952 KB
testcase_10 AC 29 ms
8,936 KB
testcase_11 AC 26 ms
8,844 KB
testcase_12 AC 25 ms
8,732 KB
testcase_13 AC 21 ms
8,560 KB
testcase_14 AC 31 ms
8,948 KB
testcase_15 AC 32 ms
9,152 KB
testcase_16 AC 31 ms
9,092 KB
testcase_17 AC 30 ms
9,072 KB
testcase_18 AC 20 ms
8,576 KB
testcase_19 AC 31 ms
8,996 KB
testcase_20 AC 19 ms
8,636 KB
testcase_21 AC 17 ms
8,596 KB
testcase_22 AC 27 ms
8,868 KB
testcase_23 AC 31 ms
8,996 KB
testcase_24 AC 30 ms
9,036 KB
testcase_25 AC 29 ms
9,124 KB
testcase_26 AC 16 ms
8,596 KB
testcase_27 AC 20 ms
8,576 KB
testcase_28 AC 28 ms
8,984 KB
testcase_29 AC 27 ms
9,020 KB
testcase_30 AC 17 ms
8,680 KB
testcase_31 AC 17 ms
8,520 KB
testcase_32 AC 24 ms
8,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
d = [-1] * N
checked = [False] * N
p = [None] * N
nxts = deque([0])
checked[0] = True

while nxts:
    pos = nxts.popleft()

    if pos == 0:
        d[pos] = 1
    else:
        d[pos] = d[p[pos]] + 1

    if pos == N - 1:
        print(d[N - 1])
        quit()

    step = bin(pos + 1).count('1')

    if pos - step >= 0 and not checked[pos - step]:
        nxts.append(pos - step)
        checked[pos - step] = True
        p[pos - step] = pos
    if pos + step < N and not checked[pos + step]:
        nxts.append(pos + step)
        checked[pos + step] = True
        p[pos + step] = pos

print(-1)
0