結果

問題 No.3 ビットすごろく
ユーザー PreginaPregina
提出日時 2023-12-03 18:38:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 427 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 72,572 KB
最終ジャッジ日時 2023-12-03 18:38:26
合計ジャッジ時間 3,689 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,332 KB
testcase_01 AC 38 ms
53,332 KB
testcase_02 AC 38 ms
53,332 KB
testcase_03 AC 57 ms
66,376 KB
testcase_04 AC 44 ms
61,400 KB
testcase_05 AC 57 ms
68,428 KB
testcase_06 AC 60 ms
66,376 KB
testcase_07 AC 56 ms
66,396 KB
testcase_08 AC 56 ms
68,456 KB
testcase_09 AC 57 ms
70,508 KB
testcase_10 AC 57 ms
70,492 KB
testcase_11 AC 58 ms
70,524 KB
testcase_12 AC 56 ms
68,444 KB
testcase_13 AC 54 ms
66,388 KB
testcase_14 AC 57 ms
70,492 KB
testcase_15 AC 58 ms
72,556 KB
testcase_16 AC 58 ms
72,572 KB
testcase_17 AC 60 ms
72,556 KB
testcase_18 AC 54 ms
66,396 KB
testcase_19 AC 60 ms
72,556 KB
testcase_20 AC 41 ms
55,484 KB
testcase_21 AC 39 ms
53,332 KB
testcase_22 AC 62 ms
70,492 KB
testcase_23 AC 62 ms
72,556 KB
testcase_24 AC 63 ms
72,556 KB
testcase_25 AC 64 ms
72,556 KB
testcase_26 AC 39 ms
53,332 KB
testcase_27 AC 55 ms
66,380 KB
testcase_28 AC 58 ms
72,572 KB
testcase_29 AC 57 ms
70,516 KB
testcase_30 AC 40 ms
55,484 KB
testcase_31 AC 40 ms
55,484 KB
testcase_32 AC 56 ms
68,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


N = int(input())
G = [[] for _ in range(N+1)]

for i in range(1, N+1):
    cnt = bin(i).count('1')
    if i+cnt <= N:
        G[i].append(i+cnt)
    if i-cnt > 0:
        G[i].append(i-cnt)

dist = [-1]*(N+1)
dist[1] = 1
que = deque([1])
while que:
    v = que.popleft()
    for nv in G[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v] + 1
            que.append(nv)

print(dist[N])
0