結果

問題 No.3 ビットすごろく
ユーザー takopom55takopom55
提出日時 2017-01-02 19:56:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 661 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 8,580 KB
最終ジャッジ日時 2023-09-14 00:15:46
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,944 KB
testcase_01 AC 18 ms
7,840 KB
testcase_02 AC 16 ms
7,920 KB
testcase_03 AC 18 ms
7,800 KB
testcase_04 AC 16 ms
7,792 KB
testcase_05 AC 20 ms
8,220 KB
testcase_06 AC 18 ms
7,788 KB
testcase_07 AC 18 ms
7,792 KB
testcase_08 AC 19 ms
7,852 KB
testcase_09 AC 22 ms
8,324 KB
testcase_10 AC 23 ms
8,452 KB
testcase_11 AC 21 ms
8,256 KB
testcase_12 AC 20 ms
8,300 KB
testcase_13 AC 18 ms
7,816 KB
testcase_14 AC 22 ms
8,412 KB
testcase_15 AC 24 ms
8,512 KB
testcase_16 AC 24 ms
8,360 KB
testcase_17 AC 23 ms
8,504 KB
testcase_18 AC 18 ms
7,784 KB
testcase_19 AC 23 ms
8,384 KB
testcase_20 AC 17 ms
7,816 KB
testcase_21 AC 17 ms
7,852 KB
testcase_22 AC 22 ms
8,424 KB
testcase_23 AC 24 ms
8,432 KB
testcase_24 AC 23 ms
8,432 KB
testcase_25 AC 23 ms
8,580 KB
testcase_26 AC 16 ms
7,792 KB
testcase_27 AC 18 ms
7,852 KB
testcase_28 AC 23 ms
8,452 KB
testcase_29 AC 21 ms
8,404 KB
testcase_30 AC 16 ms
7,780 KB
testcase_31 AC 16 ms
7,920 KB
testcase_32 AC 20 ms
8,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())
    
    route = [0] * (N + 1)
    route[1] = 1

    queue = []
    queue.append(1)

    answer = -1

    while len(queue):
        node = queue.pop(0)

        if node == N:
            answer = route[node]
            break
        
        step = bin(node).count('1')
        prev = node - step
        next = node + step

        if 0 < next <= N and route[next] == 0:
            queue.append(next)
            route[next] = route[node] + 1

        if 0 < prev <= N and route[prev] == 0:
            queue.append(prev)
            route[prev] = route[node] + 1
    
    print(answer)

if __name__ == '__main__':
    main()
0