結果

問題 No.3 ビットすごろく
ユーザー Ryushi-techRyushi-tech
提出日時 2020-06-22 18:21:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 631 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 10,296 KB
最終ジャッジ日時 2023-09-16 19:17:25
合計ジャッジ時間 2,273 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,492 KB
testcase_01 AC 18 ms
8,420 KB
testcase_02 AC 18 ms
8,492 KB
testcase_03 AC 22 ms
8,848 KB
testcase_04 AC 20 ms
8,684 KB
testcase_05 AC 27 ms
9,436 KB
testcase_06 AC 23 ms
8,904 KB
testcase_07 AC 22 ms
8,744 KB
testcase_08 AC 25 ms
9,260 KB
testcase_09 AC 29 ms
9,704 KB
testcase_10 AC 31 ms
9,936 KB
testcase_11 AC 28 ms
9,612 KB
testcase_12 AC 26 ms
9,424 KB
testcase_13 AC 22 ms
8,780 KB
testcase_14 AC 29 ms
9,816 KB
testcase_15 AC 30 ms
10,236 KB
testcase_16 AC 31 ms
10,072 KB
testcase_17 AC 32 ms
10,288 KB
testcase_18 AC 20 ms
8,772 KB
testcase_19 AC 31 ms
10,220 KB
testcase_20 AC 18 ms
8,640 KB
testcase_21 AC 18 ms
8,524 KB
testcase_22 AC 30 ms
9,872 KB
testcase_23 AC 32 ms
10,212 KB
testcase_24 AC 32 ms
10,284 KB
testcase_25 AC 32 ms
10,296 KB
testcase_26 WA -
testcase_27 AC 21 ms
8,800 KB
testcase_28 AC 30 ms
10,012 KB
testcase_29 AC 28 ms
9,672 KB
testcase_30 AC 18 ms
8,464 KB
testcase_31 AC 18 ms
8,424 KB
testcase_32 AC 27 ms
9,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
l = n.bit_length()
g = [[] for _ in range(n + 1 + l)]

for i in range(n + 1):
    x = bin(i).count("1")
    g[i].append(i + x)
    g[i].append(i - x)

par = [0] * (n + 1 + l)
chk = [False] * (n + 1 + l)
chk[0] = True
stk = deque()
stk.append(1)

while stk:
    v = stk.popleft()
    for y in g[v]:
        if chk[y]:
            continue
        if y == par[v]:
            continue
        chk[y] = True
        par[y] = v
        stk.append(y)

if not chk[n]:
    print(-1)
    exit()

cnt = 1
while n > 1:
    n = par[n]
    cnt += 1
print(cnt)

#print(chk)
#print(g)
#print(par)
0