結果

問題 No.3 ビットすごろく
ユーザー momoyuumomoyuu
提出日時 2022-03-22 02:09:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 8,992 KB
最終ジャッジ日時 2023-07-30 22:02:14
合計ジャッジ時間 3,136 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,496 KB
testcase_01 AC 19 ms
8,504 KB
testcase_02 AC 19 ms
8,596 KB
testcase_03 AC 24 ms
8,584 KB
testcase_04 AC 20 ms
8,608 KB
testcase_05 AC 32 ms
8,832 KB
testcase_06 AC 25 ms
8,596 KB
testcase_07 AC 24 ms
8,508 KB
testcase_08 AC 29 ms
8,656 KB
testcase_09 AC 35 ms
8,888 KB
testcase_10 AC 38 ms
8,820 KB
testcase_11 AC 34 ms
8,648 KB
testcase_12 AC 31 ms
8,600 KB
testcase_13 AC 24 ms
8,480 KB
testcase_14 AC 39 ms
8,940 KB
testcase_15 AC 43 ms
8,860 KB
testcase_16 AC 42 ms
8,844 KB
testcase_17 AC 43 ms
8,992 KB
testcase_18 AC 23 ms
8,616 KB
testcase_19 AC 43 ms
8,948 KB
testcase_20 AC 21 ms
8,584 KB
testcase_21 AC 19 ms
8,636 KB
testcase_22 AC 39 ms
8,868 KB
testcase_23 AC 43 ms
8,956 KB
testcase_24 AC 43 ms
8,888 KB
testcase_25 AC 43 ms
8,884 KB
testcase_26 AC 19 ms
8,420 KB
testcase_27 AC 24 ms
8,700 KB
testcase_28 AC 40 ms
8,760 KB
testcase_29 AC 35 ms
8,708 KB
testcase_30 AC 19 ms
8,424 KB
testcase_31 AC 19 ms
8,500 KB
testcase_32 AC 33 ms
8,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
def calc(n):
    s = bin(n)
    l = len(s)-2
    c = 0
    for i in range(l):
        if n>>i & 1 == 1:
            c += 1
    return c

copy = [-1 for _ in range(N)]
copy[0] = 1
used = [0 for _ in range(N)]
from collections import deque
que = deque()
que.append(1)
while que:
    i = que.popleft()
    if used[i-1] == 1:
        continue
    used[i-1] = 1
    n = calc(i)
    j = n
    if i - j > 0:
        if copy[i-j-1] == -1:
            copy[i-j-1] = copy[i-1]+1
            que.append(i-j)
    if i + j <= N : 
        if copy[i+j-1] == -1:
            copy[i+j-1] = copy[i-1]+1
            que.append(i+j)
print(copy[N-1])
0