結果

問題 No.3 ビットすごろく
ユーザー shianoshiano
提出日時 2020-06-16 21:49:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 309 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 8,812 KB
最終ジャッジ日時 2023-09-14 01:46:07
合計ジャッジ時間 3,002 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,852 KB
testcase_01 AC 15 ms
7,872 KB
testcase_02 AC 15 ms
7,876 KB
testcase_03 AC 24 ms
8,336 KB
testcase_04 AC 17 ms
8,172 KB
testcase_05 AC 45 ms
8,360 KB
testcase_06 AC 26 ms
8,196 KB
testcase_07 AC 21 ms
8,180 KB
testcase_08 AC 40 ms
8,352 KB
testcase_09 AC 60 ms
8,528 KB
testcase_10 AC 89 ms
8,684 KB
testcase_11 AC 57 ms
8,552 KB
testcase_12 AC 44 ms
8,368 KB
testcase_13 AC 23 ms
8,188 KB
testcase_14 AC 79 ms
8,632 KB
testcase_15 AC 95 ms
8,644 KB
testcase_16 AC 90 ms
8,640 KB
testcase_17 AC 94 ms
8,812 KB
testcase_18 AC 21 ms
8,200 KB
testcase_19 AC 94 ms
8,764 KB
testcase_20 AC 17 ms
8,188 KB
testcase_21 AC 15 ms
7,944 KB
testcase_22 AC 81 ms
8,580 KB
testcase_23 AC 97 ms
8,740 KB
testcase_24 AC 99 ms
8,776 KB
testcase_25 AC 97 ms
8,772 KB
testcase_26 AC 14 ms
7,844 KB
testcase_27 AC 22 ms
8,204 KB
testcase_28 AC 91 ms
8,560 KB
testcase_29 AC 57 ms
8,508 KB
testcase_30 AC 15 ms
7,848 KB
testcase_31 AC 15 ms
7,940 KB
testcase_32 AC 49 ms
8,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(410000)

n = int(input())

INF = 10000
dp = [INF]*(n+1)

def dfs(i,m):

  if dp[i] <= m:
    return
  dp[i] = m
  bc = bin(i).count("1")
    
  if 1< i+bc <=n:
    dfs(i+bc,m+1)
  if 1< i-bc <=n:    
    dfs(i-bc,m+1)

dfs(1,1)

if dp[n]==INF:
  print(-1)
else:
  print(dp[n])
0