結果

問題 No.3 ビットすごろく
ユーザー Konton7Konton7
提出日時 2019-05-17 16:27:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,754 ms / 5,000 ms
コード長 461 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 10,760 KB
実行使用メモリ 8,628 KB
最終ジャッジ日時 2023-09-14 01:20:08
合計ジャッジ時間 23,810 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,804 KB
testcase_01 AC 16 ms
7,948 KB
testcase_02 AC 16 ms
7,860 KB
testcase_03 AC 132 ms
7,956 KB
testcase_04 AC 28 ms
7,832 KB
testcase_05 AC 538 ms
8,472 KB
testcase_06 AC 163 ms
7,804 KB
testcase_07 AC 67 ms
7,800 KB
testcase_08 AC 358 ms
8,360 KB
testcase_09 AC 871 ms
8,408 KB
testcase_10 AC 1,216 ms
8,468 KB
testcase_11 AC 733 ms
8,308 KB
testcase_12 AC 539 ms
8,348 KB
testcase_13 AC 100 ms
7,908 KB
testcase_14 AC 1,130 ms
8,368 KB
testcase_15 AC 1,682 ms
8,504 KB
testcase_16 AC 1,533 ms
8,496 KB
testcase_17 AC 1,679 ms
8,532 KB
testcase_18 AC 81 ms
7,840 KB
testcase_19 AC 1,742 ms
8,512 KB
testcase_20 AC 23 ms
7,952 KB
testcase_21 AC 16 ms
7,804 KB
testcase_22 AC 1,124 ms
8,408 KB
testcase_23 AC 1,723 ms
8,624 KB
testcase_24 AC 1,754 ms
8,628 KB
testcase_25 AC 1,723 ms
8,444 KB
testcase_26 AC 16 ms
7,800 KB
testcase_27 AC 115 ms
7,856 KB
testcase_28 AC 1,435 ms
8,580 KB
testcase_29 AC 770 ms
8,396 KB
testcase_30 AC 16 ms
7,780 KB
testcase_31 AC 17 ms
7,868 KB
testcase_32 AC 655 ms
8,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

grid = [ bin(i+1).count("1") for i in range(n) ]
step = [1] + [-1 for i in range(n-1)] 
for i in range(1,n):
    s = 0
    for j in range(n):
        if step[j] == i:
            if j-grid[j] > 0 and step[j-grid[j]] == -1:
                step[j-grid[j]] = i+1
                s = 1
            if j+grid[j] < n and step[j+grid[j]] == -1:
                step[j+grid[j]] = i+1
                s = 1
    if s == 0:
        break
print(step[-1])
0