結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,524 KB
testcase_01 AC 18 ms
8,624 KB
testcase_02 AC 18 ms
8,656 KB
testcase_03 AC 22 ms
8,604 KB
testcase_04 AC 20 ms
8,576 KB
testcase_05 AC 25 ms
8,600 KB
testcase_06 AC 23 ms
8,568 KB
testcase_07 AC 20 ms
8,476 KB
testcase_08 AC 25 ms
8,620 KB
testcase_09 AC 28 ms
8,644 KB
testcase_10 AC 29 ms
8,696 KB
testcase_11 AC 27 ms
8,704 KB
testcase_12 AC 25 ms
8,772 KB
testcase_13 AC 21 ms
8,488 KB
testcase_14 AC 29 ms
8,828 KB
testcase_15 AC 32 ms
8,916 KB
testcase_16 AC 30 ms
8,864 KB
testcase_17 AC 32 ms
8,812 KB
testcase_18 AC 20 ms
8,500 KB
testcase_19 AC 32 ms
8,816 KB
testcase_20 AC 19 ms
8,624 KB
testcase_21 AC 18 ms
8,632 KB
testcase_22 AC 29 ms
8,756 KB
testcase_23 AC 31 ms
8,760 KB
testcase_24 AC 32 ms
8,816 KB
testcase_25 AC 32 ms
8,808 KB
testcase_26 AC 19 ms
8,460 KB
testcase_27 AC 21 ms
8,496 KB
testcase_28 AC 30 ms
8,732 KB
testcase_29 AC 27 ms
8,776 KB
testcase_30 AC 19 ms
8,512 KB
testcase_31 AC 19 ms
8,528 KB
testcase_32 AC 26 ms
8,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())

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

que = deque()
que.append([1,1])

while len(que)>0:
  i,m = que.popleft()
    
  if dp[i] <= m:
    continue
    
  dp[i] = m
  bc = bin(i).count("1")
    
  if 1< i+bc <=n:
    que.append([i+bc,m+1])
  if 1< i-bc <=n:    
    que.append([i-bc,m+1])

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