結果

問題 No.3 ビットすごろく
ユーザー buey_tbuey_t
提出日時 2023-04-25 18:12:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 1,257 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 90,496 KB
最終ジャッジ日時 2024-04-26 22:31:49
合計ジャッジ時間 6,947 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
84,736 KB
testcase_01 AC 133 ms
84,856 KB
testcase_02 AC 131 ms
85,020 KB
testcase_03 AC 157 ms
90,180 KB
testcase_04 AC 152 ms
90,112 KB
testcase_05 AC 158 ms
90,128 KB
testcase_06 AC 158 ms
90,112 KB
testcase_07 AC 155 ms
90,368 KB
testcase_08 AC 161 ms
90,228 KB
testcase_09 AC 159 ms
90,496 KB
testcase_10 AC 157 ms
90,112 KB
testcase_11 AC 158 ms
90,112 KB
testcase_12 AC 156 ms
90,420 KB
testcase_13 AC 156 ms
90,312 KB
testcase_14 AC 160 ms
90,104 KB
testcase_15 AC 160 ms
90,240 KB
testcase_16 AC 161 ms
90,112 KB
testcase_17 AC 159 ms
90,112 KB
testcase_18 AC 155 ms
90,112 KB
testcase_19 AC 163 ms
90,076 KB
testcase_20 AC 152 ms
90,240 KB
testcase_21 AC 131 ms
85,068 KB
testcase_22 AC 163 ms
90,240 KB
testcase_23 AC 161 ms
90,124 KB
testcase_24 AC 163 ms
90,368 KB
testcase_25 AC 163 ms
90,368 KB
testcase_26 AC 133 ms
84,952 KB
testcase_27 AC 160 ms
90,080 KB
testcase_28 AC 169 ms
90,112 KB
testcase_29 AC 163 ms
90,220 KB
testcase_30 AC 146 ms
89,480 KB
testcase_31 AC 150 ms
89,600 KB
testcase_32 AC 161 ms
90,240 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