結果

問題 No.3 ビットすごろく
ユーザー hacchahaccha
提出日時 2023-06-22 19:14:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 173 ms / 5,000 ms
コード長 348 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 11,392 KB
実行使用メモリ 17,324 KB
最終ジャッジ日時 2023-09-12 13:31:05
合計ジャッジ時間 6,425 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,212 KB
testcase_01 AC 82 ms
15,116 KB
testcase_02 AC 81 ms
15,084 KB
testcase_03 AC 92 ms
16,896 KB
testcase_04 AC 86 ms
15,384 KB
testcase_05 AC 117 ms
17,148 KB
testcase_06 AC 94 ms
17,184 KB
testcase_07 AC 87 ms
16,088 KB
testcase_08 AC 108 ms
16,952 KB
testcase_09 AC 130 ms
17,028 KB
testcase_10 AC 159 ms
17,100 KB
testcase_11 AC 127 ms
17,048 KB
testcase_12 AC 114 ms
16,960 KB
testcase_13 AC 90 ms
16,616 KB
testcase_14 AC 152 ms
17,060 KB
testcase_15 AC 170 ms
17,324 KB
testcase_16 AC 165 ms
17,264 KB
testcase_17 AC 170 ms
17,160 KB
testcase_18 AC 89 ms
16,348 KB
testcase_19 AC 173 ms
17,292 KB
testcase_20 AC 84 ms
15,124 KB
testcase_21 AC 80 ms
15,040 KB
testcase_22 AC 153 ms
17,256 KB
testcase_23 AC 171 ms
17,324 KB
testcase_24 AC 170 ms
17,076 KB
testcase_25 AC 172 ms
16,948 KB
testcase_26 AC 81 ms
15,052 KB
testcase_27 AC 93 ms
16,676 KB
testcase_28 AC 164 ms
17,008 KB
testcase_29 AC 126 ms
17,148 KB
testcase_30 AC 82 ms
15,116 KB
testcase_31 AC 83 ms
15,296 KB
testcase_32 AC 123 ms
17,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

$N = gets.to_i
$steps = Array.new($N, -1)

def popcount(n)
  n.digits(2).sum
end

def carol(n, curSteps)
  return if n <= 0 || n > $N

  if $steps[n-1] == -1 || $steps[n-1] > curSteps
     $steps[n-1] = curSteps
     counts = popcount(n)
     carol(n + counts, curSteps+1)
     carol(n - counts, curSteps+1)
  end
end

carol(1, 1)
puts $steps[$N-1]
0