結果

問題 No.915 Plus Or Multiple Operation
ユーザー yuruhiya
提出日時 2020-06-13 19:15:54
言語 Crystal
(1.14.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 354 bytes
コンパイル時間 12,266 ms
コンパイル使用メモリ 296,088 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 20:18:33
合計ジャッジ時間 12,673 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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