結果

問題 No.3 ビットすごろく
ユーザー 杉山新杉山新
提出日時 2020-08-16 19:00:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 532 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 8,920 KB
最終ジャッジ日時 2023-09-14 01:48:42
合計ジャッジ時間 2,213 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,468 KB
testcase_01 AC 19 ms
8,572 KB
testcase_02 AC 19 ms
8,424 KB
testcase_03 AC 21 ms
8,532 KB
testcase_04 AC 20 ms
8,456 KB
testcase_05 AC 23 ms
8,712 KB
testcase_06 AC 21 ms
8,584 KB
testcase_07 AC 21 ms
8,568 KB
testcase_08 AC 23 ms
8,652 KB
testcase_09 AC 26 ms
8,712 KB
testcase_10 AC 27 ms
8,828 KB
testcase_11 AC 25 ms
8,760 KB
testcase_12 AC 24 ms
8,652 KB
testcase_13 AC 21 ms
8,640 KB
testcase_14 AC 27 ms
8,728 KB
testcase_15 AC 29 ms
8,804 KB
testcase_16 AC 29 ms
8,732 KB
testcase_17 AC 29 ms
8,900 KB
testcase_18 AC 20 ms
8,572 KB
testcase_19 AC 30 ms
8,824 KB
testcase_20 AC 19 ms
8,488 KB
testcase_21 AC 18 ms
8,460 KB
testcase_22 AC 26 ms
8,804 KB
testcase_23 AC 29 ms
8,812 KB
testcase_24 AC 29 ms
8,920 KB
testcase_25 AC 29 ms
8,868 KB
testcase_26 AC 18 ms
8,512 KB
testcase_27 AC 21 ms
8,564 KB
testcase_28 AC 28 ms
8,760 KB
testcase_29 AC 25 ms
8,668 KB
testcase_30 AC 19 ms
8,452 KB
testcase_31 AC 19 ms
8,556 KB
testcase_32 AC 25 ms
8,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N = int(input())

def bfs():
    v = deque([0]*(N+1))
    v[1] = 1
    q = deque()
    q.append(1)
    while (q):
        u = q.popleft()
        if u == N:
            return v[u]
        bit1_count = "{:b}".format(u).count("1")
        v1 = u+bit1_count
        v2 = u - bit1_count
        if (0 < v1 <=N) and (v[v1]==0):
            q.append(v1)
            v[v1]=v[u]+1
        if (0<v2<=N) and(v[v2]==0):
            q.append(v2)
            v[v2] = v[u]+1
            
    return -1
print(bfs())
0