結果

問題 No.915 Plus Or Multiple Operation
ユーザー yuruhiyayuruhiya
提出日時 2020-06-13 19:15:54
言語 Crystal
(1.11.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 354 bytes
コンパイル時間 19,523 ms
コンパイル使用メモリ 256,788 KB
実行使用メモリ 4,432 KB
最終ジャッジ日時 2023-09-13 10:48:20
合計ジャッジ時間 18,124 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,396 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 3 ms
4,416 KB
testcase_05 AC 3 ms
4,432 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,420 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,432 KB
testcase_12 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

read_line.to_i.times do
  a, b, c = read_line.split.map(&.to_i64)
  if c == 1
    puts -1
    next
  end
  dfs = Hash(Int64, Int64).new do |h, n|
    if n == 0
      h[n] = 0
    elsif n % c == 0
      h[n] = {h[n // c] + b, (n + c - 2)//(c - 1)*b}.min
    else
      h[n] = {h[n - n % c] + b, (n + c - 2)//(c - 1)*b}.min
    end
  end
  puts dfs[a]
end
0