結果

問題 No.3 ビットすごろく
ユーザー yozayoza
提出日時 2014-11-14 20:41:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 491 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2023-08-30 03:40:45
合計ジャッジ時間 2,573 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,980 KB
testcase_01 AC 16 ms
7,796 KB
testcase_02 AC 15 ms
7,896 KB
testcase_03 AC 19 ms
7,948 KB
testcase_04 AC 17 ms
7,888 KB
testcase_05 AC 24 ms
8,312 KB
testcase_06 AC 20 ms
7,952 KB
testcase_07 AC 18 ms
7,820 KB
testcase_08 AC 23 ms
8,252 KB
testcase_09 AC 26 ms
8,440 KB
testcase_10 AC 29 ms
8,416 KB
testcase_11 AC 26 ms
8,432 KB
testcase_12 AC 25 ms
8,304 KB
testcase_13 AC 19 ms
7,832 KB
testcase_14 AC 28 ms
8,360 KB
testcase_15 AC 31 ms
8,444 KB
testcase_16 AC 29 ms
8,452 KB
testcase_17 AC 31 ms
8,576 KB
testcase_18 AC 19 ms
7,840 KB
testcase_19 AC 30 ms
8,424 KB
testcase_20 AC 17 ms
7,868 KB
testcase_21 AC 16 ms
7,840 KB
testcase_22 AC 28 ms
8,336 KB
testcase_23 AC 31 ms
8,456 KB
testcase_24 AC 31 ms
8,536 KB
testcase_25 AC 31 ms
8,508 KB
testcase_26 WA -
testcase_27 AC 20 ms
7,788 KB
testcase_28 AC 30 ms
8,364 KB
testcase_29 AC 26 ms
8,420 KB
testcase_30 AC 16 ms
7,836 KB
testcase_31 AC 16 ms
7,788 KB
testcase_32 AC 25 ms
8,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
b = [bin(i+1).count("1") for i in range(n)]

cell = [-1] * n
cell[0] = 0
queue = [[0, 2]]
while queue:
    num, cost = queue.pop(0)
    if num == n - 1:
        break
    if num - b[num] >= 0 and cell[num - b[num]] == -1:
        cell[num - b[num]] = cost
        queue.append([num - b[num], cost + 1])
    if num + b[num] < n and cell[num + b[num]] == -1:
        cell[num + b[num]] = cost
        queue.append([num + b[num], cost + 1])

print(cell[n-1])
0