結果

問題 No.3 ビットすごろく
ユーザー buey_tbuey_t
提出日時 2023-04-25 18:12:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 320 ms / 5,000 ms
コード長 1,257 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 86,020 KB
最終ジャッジ日時 2023-08-09 07:53:35
合計ジャッジ時間 10,686 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 232 ms
82,576 KB
testcase_01 AC 232 ms
82,620 KB
testcase_02 AC 232 ms
82,852 KB
testcase_03 AC 245 ms
84,368 KB
testcase_04 AC 239 ms
83,584 KB
testcase_05 AC 250 ms
84,704 KB
testcase_06 AC 247 ms
84,420 KB
testcase_07 AC 247 ms
83,768 KB
testcase_08 AC 248 ms
84,656 KB
testcase_09 AC 248 ms
85,420 KB
testcase_10 AC 253 ms
85,984 KB
testcase_11 AC 256 ms
85,276 KB
testcase_12 AC 256 ms
84,972 KB
testcase_13 AC 259 ms
84,032 KB
testcase_14 AC 254 ms
85,636 KB
testcase_15 AC 259 ms
85,884 KB
testcase_16 AC 257 ms
85,600 KB
testcase_17 AC 264 ms
85,756 KB
testcase_18 AC 256 ms
83,956 KB
testcase_19 AC 255 ms
85,916 KB
testcase_20 AC 244 ms
83,588 KB
testcase_21 AC 236 ms
82,488 KB
testcase_22 AC 260 ms
85,592 KB
testcase_23 AC 263 ms
85,940 KB
testcase_24 AC 263 ms
85,860 KB
testcase_25 AC 262 ms
86,020 KB
testcase_26 AC 244 ms
82,704 KB
testcase_27 AC 264 ms
84,180 KB
testcase_28 AC 320 ms
86,004 KB
testcase_29 AC 260 ms
85,420 KB
testcase_30 AC 244 ms
83,312 KB
testcase_31 AC 237 ms
83,228 KB
testcase_32 AC 256 ms
85,048 KB
権限があれば一括ダウンロードができます

ソースコード

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