結果

問題 No.3 ビットすごろく
ユーザー にゃんにゃん
提出日時 2022-02-13 03:23:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 372 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 10,752 KB
実行使用メモリ 8,980 KB
最終ジャッジ日時 2023-09-11 15:17:24
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,524 KB
testcase_01 AC 18 ms
8,520 KB
testcase_02 AC 18 ms
8,632 KB
testcase_03 AC 20 ms
8,708 KB
testcase_04 AC 19 ms
8,500 KB
testcase_05 AC 23 ms
8,820 KB
testcase_06 AC 21 ms
8,588 KB
testcase_07 AC 20 ms
8,596 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 23 ms
8,776 KB
testcase_13 AC 20 ms
8,492 KB
testcase_14 AC 27 ms
8,824 KB
testcase_15 AC 28 ms
8,904 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 20 ms
8,516 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 18 ms
8,648 KB
testcase_22 AC 26 ms
8,776 KB
testcase_23 AC 28 ms
8,800 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 17 ms
8,648 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 17 ms
8,652 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
cost = [-1] * (N + 1)
cost[1] = 1
que = deque([1])

while que:
    a = que.pop()
    b = bin(a).count('1')

    if a - b > 0 and cost[a - b] == -1:
        cost[a - b] = cost[a] + 1
        que.append(a - b)
    if a + b <= N and cost[a + b] == -1:
        cost[a + b] = cost[a] + 1
        que.append(a + b)

print(cost[N])
0