結果

問題 No.3 ビットすごろく
ユーザー nakamura sosukenakamura sosuke
提出日時 2019-07-04 19:06:35
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 391 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 11,896 KB
実行使用メモリ 16,460 KB
最終ジャッジ日時 2023-10-19 09:18:59
合計ジャッジ時間 4,789 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
16,084 KB
testcase_01 AC 87 ms
16,084 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 89 ms
16,084 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 88 ms
16,084 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 87 ms
16,084 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 85 ms
16,084 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 87 ms
16,084 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 84 ms
16,084 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)

p dp[-1]
0