結果

問題 No.915 Plus Or Multiple Operation
ユーザー yuruhiyayuruhiya
提出日時 2020-08-12 19:36:47
言語 Bash
(Bash 5.1.16)
結果
MLE  
実行時間 -
コード長 404 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 1,259,476 KB
最終ジャッジ日時 2024-04-24 19:00:09
合計ジャッジ時間 6,712 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

crystal eval 'require "big"
read_line.to_i.times do
  a, b, c = read_line.split.map(&.to_big_i)
  if c == 1
    puts -1
    next
  end
  dfs = Hash(BigInt, BigInt).new do |h, n|
    if n == 0
      h[n] = 0.to_big_i
    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