結果

問題 No.3 ビットすごろく
ユーザー momoyuumomoyuu
提出日時 2022-03-22 02:09:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-17 23:15:47
合計ジャッジ時間 2,635 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,752 KB
testcase_01 AC 35 ms
10,752 KB
testcase_02 AC 33 ms
10,752 KB
testcase_03 AC 36 ms
11,008 KB
testcase_04 AC 33 ms
10,624 KB
testcase_05 AC 43 ms
10,880 KB
testcase_06 AC 37 ms
10,752 KB
testcase_07 AC 35 ms
10,880 KB
testcase_08 AC 42 ms
10,880 KB
testcase_09 AC 47 ms
11,008 KB
testcase_10 AC 50 ms
11,008 KB
testcase_11 AC 45 ms
10,880 KB
testcase_12 AC 44 ms
11,008 KB
testcase_13 AC 36 ms
10,880 KB
testcase_14 AC 49 ms
11,136 KB
testcase_15 AC 54 ms
11,008 KB
testcase_16 AC 52 ms
11,136 KB
testcase_17 AC 54 ms
11,136 KB
testcase_18 AC 35 ms
10,752 KB
testcase_19 AC 56 ms
11,264 KB
testcase_20 AC 32 ms
10,752 KB
testcase_21 AC 31 ms
10,624 KB
testcase_22 AC 50 ms
11,008 KB
testcase_23 AC 54 ms
11,264 KB
testcase_24 AC 54 ms
11,136 KB
testcase_25 AC 54 ms
11,008 KB
testcase_26 AC 31 ms
10,880 KB
testcase_27 AC 36 ms
11,008 KB
testcase_28 AC 53 ms
11,264 KB
testcase_29 AC 46 ms
11,008 KB
testcase_30 AC 31 ms
10,624 KB
testcase_31 AC 31 ms
10,880 KB
testcase_32 AC 45 ms
11,008 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