結果

問題 No.3 ビットすごろく
ユーザー tachyon777tachyon777
提出日時 2020-02-13 13:33:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 213 ms / 5,000 ms
コード長 775 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 81,244 KB
最終ジャッジ日時 2023-09-14 01:37:49
合計ジャッジ時間 7,044 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
80,532 KB
testcase_01 AC 138 ms
80,908 KB
testcase_02 AC 141 ms
80,540 KB
testcase_03 AC 163 ms
81,024 KB
testcase_04 AC 139 ms
80,804 KB
testcase_05 AC 174 ms
80,748 KB
testcase_06 AC 148 ms
80,724 KB
testcase_07 AC 134 ms
80,160 KB
testcase_08 AC 156 ms
81,004 KB
testcase_09 AC 175 ms
80,872 KB
testcase_10 AC 198 ms
80,812 KB
testcase_11 AC 172 ms
80,552 KB
testcase_12 AC 165 ms
80,804 KB
testcase_13 AC 140 ms
80,960 KB
testcase_14 AC 193 ms
80,600 KB
testcase_15 AC 198 ms
80,768 KB
testcase_16 AC 190 ms
81,056 KB
testcase_17 AC 198 ms
80,948 KB
testcase_18 AC 143 ms
80,772 KB
testcase_19 AC 198 ms
80,956 KB
testcase_20 AC 127 ms
80,692 KB
testcase_21 AC 124 ms
80,732 KB
testcase_22 AC 199 ms
80,804 KB
testcase_23 AC 209 ms
81,244 KB
testcase_24 AC 202 ms
80,800 KB
testcase_25 AC 203 ms
80,812 KB
testcase_26 AC 124 ms
80,724 KB
testcase_27 AC 144 ms
80,748 KB
testcase_28 AC 213 ms
81,004 KB
testcase_29 AC 178 ms
80,556 KB
testcase_30 AC 121 ms
80,388 KB
testcase_31 AC 121 ms
80,852 KB
testcase_32 AC 188 ms
80,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

n = int(input())

lst1 = []
for i in range(1,100001):
    dig = len(bin(i))-2
    res = 0
    for j in range(dig):
        if i >> j & 1:
            res += 1
    lst1.append(res)

visited = [0]*n
visited[0] = 1
queue = [(1,0)] #res,now
ans = -1

heapq.heapify(queue)

while queue:
    res,now = heapq.heappop(queue)
    if now == n-1: #最小から取り出してるので、初めに行き着いたやつが答え
        ans = res
        break
    if 0 <= now-lst1[now] and visited[now-lst1[now]] == 0:
        visited[now-lst1[now]] = 1
        heapq.heappush(queue,(res+1,now-lst1[now]))
    if now+lst1[now] < n and visited[now+lst1[now]] == 0:
        visited[now+lst1[now]] = 1
        heapq.heappush(queue,(res+1,now+lst1[now]))

print(ans)
    
    
0