結果

問題 No.3 ビットすごろく
ユーザー nakamura sosukenakamura sosuke
提出日時 2019-07-04 19:08:13
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 425 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 11,732 KB
実行使用メモリ 16,316 KB
最終ジャッジ日時 2023-10-19 09:32:07
合計ジャッジ時間 5,511 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
15,944 KB
testcase_01 AC 88 ms
15,948 KB
testcase_02 AC 90 ms
15,948 KB
testcase_03 AC 92 ms
15,952 KB
testcase_04 AC 92 ms
15,948 KB
testcase_05 AC 95 ms
16,004 KB
testcase_06 AC 93 ms
15,948 KB
testcase_07 AC 90 ms
15,948 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 93 ms
16,000 KB
testcase_13 AC 92 ms
15,948 KB
testcase_14 AC 96 ms
16,268 KB
testcase_15 AC 96 ms
16,316 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 91 ms
15,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 87 ms
15,948 KB
testcase_22 AC 94 ms
16,268 KB
testcase_23 AC 95 ms
16,316 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 87 ms
15,948 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 90 ms
15,948 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

N = gets.to_i

dp = Array.new(N+1)
dp[0], dp[1] = 0, 1

def move(dp, from)
  dist = from.to_s(2).count('1')
  if from + dist <= N && dp[from + dist] == nil
    dp[from + dist] = dp[from] + 1
    dp = move(dp, from + dist)
  end
  if from - dist >= 0 && dp[from - dist] == nil
    dp[from - dist] = dp[from] + 1
    dp = move(dp, from - dist)
  end
  return dp
end

dp = move(dp, 1)

if dp[-1]
  puts dp[-1]
else
  puts -1
end
0