結果

問題 No.3 ビットすごろく
ユーザー KudeKude
提出日時 2020-09-03 06:52:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 298 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 77,984 KB
最終ジャッジ日時 2023-09-14 01:50:05
合計ジャッジ時間 4,998 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,680 KB
testcase_01 AC 89 ms
71,748 KB
testcase_02 AC 90 ms
71,636 KB
testcase_03 AC 107 ms
77,704 KB
testcase_04 AC 100 ms
77,432 KB
testcase_05 AC 104 ms
77,292 KB
testcase_06 AC 104 ms
77,316 KB
testcase_07 AC 101 ms
77,480 KB
testcase_08 AC 106 ms
77,588 KB
testcase_09 AC 104 ms
77,348 KB
testcase_10 AC 106 ms
77,780 KB
testcase_11 AC 106 ms
77,984 KB
testcase_12 AC 104 ms
77,612 KB
testcase_13 AC 105 ms
77,712 KB
testcase_14 AC 105 ms
77,632 KB
testcase_15 AC 106 ms
77,624 KB
testcase_16 AC 106 ms
77,380 KB
testcase_17 AC 105 ms
77,684 KB
testcase_18 AC 102 ms
77,828 KB
testcase_19 AC 107 ms
77,568 KB
testcase_20 AC 91 ms
71,812 KB
testcase_21 AC 88 ms
71,468 KB
testcase_22 AC 102 ms
77,684 KB
testcase_23 AC 103 ms
77,568 KB
testcase_24 AC 104 ms
77,564 KB
testcase_25 AC 103 ms
77,528 KB
testcase_26 AC 89 ms
71,592 KB
testcase_27 AC 102 ms
77,268 KB
testcase_28 AC 106 ms
77,720 KB
testcase_29 AC 109 ms
77,636 KB
testcase_30 AC 91 ms
71,600 KB
testcase_31 AC 89 ms
71,868 KB
testcase_32 AC 102 ms
77,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n = int(input())
dp = [-1] * (n + 1)
dp[1] = 1
q = deque()
q.append(1)
while q:
    i = q.popleft()
    dist = bin(i).count('1')
    for j in i - dist, i + dist:
        if 1 <= j <= n and dp[j] == -1:
            dp[j] = dp[i] + 1
            q.append(j)
print(dp[n])
0