結果

問題 No.3 ビットすごろく
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-11-07 23:55:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 672 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 8,868 KB
最終ジャッジ日時 2023-09-13 23:27:56
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,528 KB
testcase_01 AC 19 ms
8,440 KB
testcase_02 AC 19 ms
8,420 KB
testcase_03 AC 21 ms
8,532 KB
testcase_04 AC 19 ms
8,596 KB
testcase_05 AC 23 ms
8,644 KB
testcase_06 AC 21 ms
8,488 KB
testcase_07 AC 21 ms
8,452 KB
testcase_08 AC 23 ms
8,476 KB
testcase_09 AC 25 ms
8,624 KB
testcase_10 AC 25 ms
8,652 KB
testcase_11 AC 24 ms
8,764 KB
testcase_12 AC 24 ms
8,564 KB
testcase_13 AC 20 ms
8,524 KB
testcase_14 AC 25 ms
8,732 KB
testcase_15 AC 27 ms
8,792 KB
testcase_16 AC 27 ms
8,696 KB
testcase_17 AC 27 ms
8,660 KB
testcase_18 AC 21 ms
8,572 KB
testcase_19 AC 27 ms
8,796 KB
testcase_20 AC 19 ms
8,500 KB
testcase_21 AC 19 ms
8,440 KB
testcase_22 AC 25 ms
8,808 KB
testcase_23 AC 27 ms
8,776 KB
testcase_24 AC 28 ms
8,800 KB
testcase_25 AC 27 ms
8,792 KB
testcase_26 AC 20 ms
8,628 KB
testcase_27 AC 20 ms
8,532 KB
testcase_28 AC 26 ms
8,868 KB
testcase_29 AC 24 ms
8,788 KB
testcase_30 AC 19 ms
8,504 KB
testcase_31 AC 19 ms
8,600 KB
testcase_32 AC 24 ms
8,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


def get_minimum_moves(n):
    visits = collections.deque(0 for x in range(n + 1))
    queue = collections.deque()
    visits[1] = 1
    queue.append(1)
    while len(queue) > 0:
        u = queue.popleft()
        if u == n:
            return visits[u]
        else:
            bitcount = bin(u).count("1")
            for v in (u + bitcount, u - bitcount):
                if 0 < v <= n and visits[v] == 0:
                    queue.append(v)
                    visits[v] = visits[u] + 1
    return -1


def main():
    print(get_minimum_moves(int(input())))


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