結果

問題 No.3 ビットすごろく
ユーザー あかしあみどりあかしあみどり
提出日時 2023-02-15 21:32:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 5,000 ms
コード長 1,178 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 80,200 KB
最終ジャッジ日時 2023-09-25 05:38:35
合計ジャッジ時間 6,005 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,380 KB
testcase_01 AC 75 ms
71,268 KB
testcase_02 AC 76 ms
71,212 KB
testcase_03 AC 120 ms
77,932 KB
testcase_04 AC 89 ms
76,488 KB
testcase_05 AC 131 ms
79,024 KB
testcase_06 AC 117 ms
78,372 KB
testcase_07 AC 105 ms
77,748 KB
testcase_08 AC 128 ms
78,596 KB
testcase_09 AC 135 ms
79,356 KB
testcase_10 AC 136 ms
79,332 KB
testcase_11 AC 131 ms
79,184 KB
testcase_12 AC 130 ms
79,076 KB
testcase_13 AC 107 ms
77,800 KB
testcase_14 AC 136 ms
79,324 KB
testcase_15 AC 145 ms
79,952 KB
testcase_16 AC 141 ms
79,656 KB
testcase_17 AC 143 ms
80,180 KB
testcase_18 AC 104 ms
77,828 KB
testcase_19 AC 143 ms
80,140 KB
testcase_20 AC 81 ms
76,300 KB
testcase_21 AC 73 ms
71,324 KB
testcase_22 AC 135 ms
79,444 KB
testcase_23 AC 143 ms
79,964 KB
testcase_24 AC 145 ms
79,964 KB
testcase_25 AC 142 ms
80,200 KB
testcase_26 AC 75 ms
71,280 KB
testcase_27 AC 110 ms
77,852 KB
testcase_28 AC 138 ms
79,480 KB
testcase_29 AC 129 ms
79,400 KB
testcase_30 AC 76 ms
71,308 KB
testcase_31 AC 75 ms
71,500 KB
testcase_32 AC 129 ms
79,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def oi(): return int(input())
def os(): return input()
def mi(): return list(map(int, input().split()))

# import sys
# input = sys.stdin.readline
# import sys
# sys.setrecursionlimit(10**8)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
input_count = 0

input_count = 0
N = oi()
maps = {i:[] for i in range(1, N + 1)}
for i in range(1, N+1):
    count = 0
    j = i
    while j:
        if j%2==1:
            count += 1
        j //= 2

    if i-count >0:
        maps[i].append((i-count, 1))
    if i+count <=N:
        maps[i].append((i+count,1))
# V: 頂点数
# g[v] = {(w, cost)}:
#     頂点vから遷移可能な頂点(w)とそのコスト(cost)
# r: 始点の頂点
 
from heapq import heappush, heappop
INF = float("inf")
def dijkstra(N, G, s):
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist
dist = dijkstra(N+1, maps, 1)
if dist[N] != INF:
    print(dist[N]+1)
else:
    print(-1)
0