結果

問題 No.3 ビットすごろく
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-11-28 07:20:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 543 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 74,884 KB
最終ジャッジ日時 2024-10-05 02:57:34
合計ジャッジ時間 2,924 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import *
from functools import *
from itertools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N = int(input())
dist = defaultdict(lambda: -1)
v = deque()
dist[1]=1
v.append(1)
while v:
    x = v.popleft()
    delta = bin(x).count('1')
    
    e = [x-delta,x+delta]
    
    for ix in e:
        if dist[ix]!=-1:
            continue
        if ix>N:
            continue
        dist[ix]=dist[x]+1
        v.append(ix)
print(dist[N])
0