結果

問題 No.3 ビットすごろく
ユーザー zombietanzombietan
提出日時 2016-04-28 18:33:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 612 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 8,964 KB
最終ジャッジ日時 2023-09-13 23:51:23
合計ジャッジ時間 2,636 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,844 KB
testcase_01 AC 16 ms
7,892 KB
testcase_02 AC 16 ms
7,848 KB
testcase_03 AC 18 ms
8,236 KB
testcase_04 AC 18 ms
7,824 KB
testcase_05 AC 19 ms
8,392 KB
testcase_06 AC 18 ms
8,212 KB
testcase_07 AC 17 ms
7,900 KB
testcase_08 AC 19 ms
8,228 KB
testcase_09 AC 21 ms
8,904 KB
testcase_10 AC 22 ms
8,780 KB
testcase_11 AC 20 ms
8,412 KB
testcase_12 AC 20 ms
8,292 KB
testcase_13 AC 18 ms
8,332 KB
testcase_14 AC 20 ms
8,964 KB
testcase_15 AC 22 ms
8,852 KB
testcase_16 AC 22 ms
8,828 KB
testcase_17 AC 22 ms
8,860 KB
testcase_18 AC 17 ms
8,212 KB
testcase_19 AC 23 ms
8,940 KB
testcase_20 AC 18 ms
7,828 KB
testcase_21 AC 17 ms
7,760 KB
testcase_22 AC 21 ms
8,800 KB
testcase_23 AC 22 ms
8,900 KB
testcase_24 AC 22 ms
8,788 KB
testcase_25 AC 22 ms
8,836 KB
testcase_26 AC 17 ms
7,780 KB
testcase_27 AC 18 ms
8,376 KB
testcase_28 AC 21 ms
8,784 KB
testcase_29 AC 20 ms
8,836 KB
testcase_30 AC 17 ms
7,772 KB
testcase_31 AC 17 ms
7,896 KB
testcase_32 AC 19 ms
8,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

def bfs(start, end):
    queue = [start]
    visited = set()
    c = 0
    while queue:
        n = []
        c += 1
        for i in queue:
            if i == end:
                return c
            b1 = bin(i).count('1')
            av = i + b1
            sv = i - b1
            if av <= end and av not in visited:
                visited.add(av)
                n.append(av)
            if sv > 1 and sv not in visited:
                visited.add(sv)
                n.append(sv)
        queue = n
    return -1
            
            
if __name__ == '__main__':
    print(bfs(1,N))
0