結果

問題 No.3 ビットすごろく
ユーザー mkawa2mkawa2
提出日時 2020-01-02 23:38:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 180 ms / 5,000 ms
コード長 1,167 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 30,344 KB
最終ジャッジ日時 2023-09-14 01:34:32
合計ジャッジ時間 7,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
30,052 KB
testcase_01 AC 138 ms
29,996 KB
testcase_02 AC 140 ms
29,976 KB
testcase_03 AC 146 ms
30,056 KB
testcase_04 AC 142 ms
29,936 KB
testcase_05 AC 158 ms
30,104 KB
testcase_06 AC 148 ms
30,024 KB
testcase_07 AC 144 ms
30,020 KB
testcase_08 AC 153 ms
30,048 KB
testcase_09 AC 164 ms
30,140 KB
testcase_10 AC 169 ms
30,228 KB
testcase_11 AC 161 ms
30,080 KB
testcase_12 AC 160 ms
30,128 KB
testcase_13 AC 144 ms
30,008 KB
testcase_14 AC 165 ms
30,184 KB
testcase_15 AC 175 ms
30,080 KB
testcase_16 AC 174 ms
30,216 KB
testcase_17 AC 173 ms
30,228 KB
testcase_18 AC 144 ms
29,932 KB
testcase_19 AC 177 ms
30,172 KB
testcase_20 AC 146 ms
29,960 KB
testcase_21 AC 144 ms
29,976 KB
testcase_22 AC 172 ms
30,184 KB
testcase_23 AC 180 ms
30,288 KB
testcase_24 AC 175 ms
30,248 KB
testcase_25 AC 172 ms
30,344 KB
testcase_26 AC 137 ms
29,920 KB
testcase_27 AC 144 ms
30,048 KB
testcase_28 AC 173 ms
30,172 KB
testcase_29 AC 162 ms
30,088 KB
testcase_30 AC 136 ms
29,920 KB
testcase_31 AC 139 ms
29,824 KB
testcase_32 AC 159 ms
29,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import *
from bisect import *
#from math import *
from collections import *
from heapq import *
from random import *
from decimal import *
import numpy as np
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    inf=10**5
    n=II()
    dp=[inf]*(n+1)
    dp[1]=1
    for _ in range(10):
        for i in range(1,n+1):
            cnt=dp[i]
            if cnt==inf:continue
            d=bin(i).count("1")
            if i-d>=1 and cnt+1<dp[i-d]:dp[i-d]=cnt+1
            if i+d<=n and cnt+1<dp[i+d]:dp[i+d]=cnt+1
    if dp[n]==inf:print(-1)
    else:print(dp[n])

main()
0