結果

問題 No.3 ビットすごろく
ユーザー buey_tbuey_t
提出日時 2023-04-25 18:12:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 1,257 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 90,800 KB
最終ジャッジ日時 2024-11-14 14:15:53
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
import sys
input = sys.stdin.readline
# .rstrip()
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353

#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!


'''
ダブリング?



'''

N = int(input())

G = [set() for _ in range(N+1)]

for i in range(1,N+1):
    cnt = 0
    for j in range(60):
        if (i>>j)&1:
            cnt += 1
    if i+cnt <= N:
        G[i].add(i+cnt)
    if i-cnt >= 1:
        G[i].add(i-cnt)

Q = deque()
Q.append((1,1))
seen = [-1]*(N+1)

while len(Q) > 0:
    pos,cnt = Q.popleft()
    
    seen[pos] = cnt
    
    for nx in G[pos]:
        if seen[nx] == -1:
            Q.append((nx,cnt+1))
            seen[nx] = cnt+1

print(seen[N])













0