結果

問題 No.3 ビットすごろく
ユーザー brthyyjpbrthyyjp
提出日時 2021-10-31 13:29:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 461 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 68,864 KB
最終ジャッジ日時 2024-04-17 06:23:11
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,376 KB
testcase_01 AC 41 ms
53,248 KB
testcase_02 AC 41 ms
53,248 KB
testcase_03 AC 51 ms
62,848 KB
testcase_04 AC 42 ms
54,400 KB
testcase_05 AC 56 ms
66,432 KB
testcase_06 AC 49 ms
63,104 KB
testcase_07 AC 49 ms
62,464 KB
testcase_08 AC 54 ms
65,664 KB
testcase_09 AC 61 ms
67,456 KB
testcase_10 AC 58 ms
67,968 KB
testcase_11 AC 56 ms
67,200 KB
testcase_12 AC 53 ms
66,304 KB
testcase_13 AC 48 ms
62,720 KB
testcase_14 AC 57 ms
67,968 KB
testcase_15 AC 56 ms
68,736 KB
testcase_16 AC 57 ms
68,608 KB
testcase_17 AC 58 ms
68,736 KB
testcase_18 AC 49 ms
62,720 KB
testcase_19 AC 58 ms
68,608 KB
testcase_20 AC 42 ms
53,888 KB
testcase_21 AC 41 ms
53,632 KB
testcase_22 AC 56 ms
67,840 KB
testcase_23 AC 57 ms
68,864 KB
testcase_24 AC 59 ms
68,864 KB
testcase_25 AC 59 ms
68,480 KB
testcase_26 AC 41 ms
53,504 KB
testcase_27 AC 48 ms
62,720 KB
testcase_28 AC 63 ms
68,480 KB
testcase_29 AC 61 ms
66,688 KB
testcase_30 AC 44 ms
53,248 KB
testcase_31 AC 47 ms
53,504 KB
testcase_32 AC 62 ms
66,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
from collections  import deque
q = deque([])
q.append(1)
INF = 10**18
dist = [INF]*(n+1)
dist[1] = 1
while q:
    v = q.popleft()
    a = format(v, 'b').count('1')
    if 1 <= v-a <= n:
        if dist[v-a] == INF:
            q.append(v-a)
            dist[v-a] = dist[v]+1
    if 1 <= v+a <= n:
        if dist[v+a] == INF:
            q.append(v+a)
            dist[v+a] = dist[v]+1
if dist[n] != INF:
    print(dist[n])
else:
    print(-1)
0