結果

問題 No.3 ビットすごろく
コンテスト
ユーザー mkawa2
提出日時 2020-01-02 23:15:28
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 499 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 346 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 312,108 KB
最終ジャッジ日時 2026-05-16 18:45:03
合計ジャッジ時間 10,548 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import *
import sys

def II(): return int(sys.stdin.readline())

def main():
    n=II()
    hp=[]
    heappush(hp,[1,1])
    cnt=[-1]*(n+1)
    while hp:
        c,u=heappop(hp)
        if u==n:
            print(c)
            exit()
        d=bin(u).count("1")
        if u+d==n or u-d==n:
            print(c+1)
            exit()
        cnt[u]=c
        if u+d<=n and cnt[u+d]==-1:heappush(hp,[c+1,u+d])
        if u-d>1 and cnt[u-d]==-1:heappush(hp,[c+1,u-d])
    print(-1)

main()
0