結果

問題 No.3 ビットすごろく
ユーザー mkawa2
提出日時 2020-01-02 23:15:28
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 499 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 314,228 KB
最終ジャッジ日時 2024-11-22 18:38:48
合計ジャッジ時間 100,343 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 TLE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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