結果

問題 No.3 ビットすごろく
ユーザー ryusukeryusuke
提出日時 2022-02-08 00:02:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 495 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 77,988 KB
最終ジャッジ日時 2023-09-04 18:01:03
合計ジャッジ時間 5,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,724 KB
testcase_01 AC 89 ms
71,752 KB
testcase_02 AC 87 ms
71,336 KB
testcase_03 AC 100 ms
77,496 KB
testcase_04 AC 96 ms
77,568 KB
testcase_05 AC 103 ms
77,880 KB
testcase_06 AC 102 ms
77,740 KB
testcase_07 AC 101 ms
77,716 KB
testcase_08 AC 102 ms
77,764 KB
testcase_09 AC 103 ms
77,392 KB
testcase_10 AC 103 ms
77,724 KB
testcase_11 AC 104 ms
77,608 KB
testcase_12 AC 102 ms
77,764 KB
testcase_13 AC 103 ms
77,736 KB
testcase_14 AC 103 ms
77,564 KB
testcase_15 AC 106 ms
77,812 KB
testcase_16 AC 105 ms
77,700 KB
testcase_17 AC 106 ms
77,880 KB
testcase_18 AC 102 ms
77,580 KB
testcase_19 AC 107 ms
77,808 KB
testcase_20 AC 98 ms
77,428 KB
testcase_21 AC 91 ms
71,648 KB
testcase_22 AC 104 ms
77,788 KB
testcase_23 AC 108 ms
77,784 KB
testcase_24 AC 109 ms
77,392 KB
testcase_25 AC 107 ms
77,832 KB
testcase_26 AC 88 ms
71,392 KB
testcase_27 AC 103 ms
77,708 KB
testcase_28 AC 107 ms
77,988 KB
testcase_29 AC 103 ms
77,796 KB
testcase_30 AC 94 ms
76,888 KB
testcase_31 AC 95 ms
76,892 KB
testcase_32 AC 104 ms
77,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())

dist = [0] * (n + 1)
dist[1] = 1

q = deque([1])
while q:
    v = q.popleft()
    cnt = 0
    for i in range(60):
        if v >> i & 1:
            cnt += 1

    a = v - cnt
    if 1 <= a <= n:
        if dist[a] == 0:
            dist[a] = dist[v] + 1
            q.append(a)

    b = v + cnt
    if 1 <= b <= n:
        if dist[b] == 0:
            dist[b] = dist[v] + 1
            q.append(b)

print(dist[-1]) if dist[-1] != 0 else print(-1)
0