結果

問題 No.3 ビットすごろく
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-10-12 21:40:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 473 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 81,284 KB
実行使用メモリ 72,280 KB
最終ジャッジ日時 2023-10-17 10:39:40
合計ジャッジ時間 4,372 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,244 KB
testcase_01 AC 41 ms
53,244 KB
testcase_02 AC 41 ms
53,244 KB
testcase_03 AC 100 ms
68,164 KB
testcase_04 AC 48 ms
61,180 KB
testcase_05 AC 61 ms
70,232 KB
testcase_06 AC 60 ms
68,184 KB
testcase_07 AC 57 ms
66,116 KB
testcase_08 AC 61 ms
68,184 KB
testcase_09 AC 62 ms
70,232 KB
testcase_10 AC 63 ms
72,280 KB
testcase_11 AC 62 ms
70,232 KB
testcase_12 AC 60 ms
70,232 KB
testcase_13 AC 57 ms
66,124 KB
testcase_14 AC 62 ms
72,280 KB
testcase_15 AC 64 ms
72,280 KB
testcase_16 AC 63 ms
72,280 KB
testcase_17 AC 65 ms
72,280 KB
testcase_18 AC 59 ms
66,124 KB
testcase_19 AC 64 ms
72,280 KB
testcase_20 AC 43 ms
55,316 KB
testcase_21 AC 41 ms
53,268 KB
testcase_22 AC 62 ms
72,280 KB
testcase_23 AC 63 ms
72,280 KB
testcase_24 AC 64 ms
72,280 KB
testcase_25 AC 65 ms
72,280 KB
testcase_26 AC 42 ms
53,268 KB
testcase_27 AC 60 ms
68,184 KB
testcase_28 AC 63 ms
72,280 KB
testcase_29 AC 62 ms
70,232 KB
testcase_30 AC 43 ms
55,316 KB
testcase_31 AC 42 ms
55,316 KB
testcase_32 AC 61 ms
70,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
l = [[] for _ in range(n)]
for i in range(n):
    bl = bin((i+1)).count("1")
    a = (i+1) + bl
    b = (i+1) - bl
    if a <= n:
        l[i].append(a-1)
    if b >= 1:
        l[i].append(b-1)
from collections import deque
q = deque([[0,1]])
vis = [-1] * n
vis[0] = 1
while q:
    node,cnt = q.popleft()
#     print(q,node,cnt)
    for nd in l[node]:
        if vis[nd] == -1:
            vis[nd] = cnt + 1
            q.append([nd,cnt+1])
print(vis[-1])
0