結果

問題 No.161 制限ジャンケン
ユーザー norioc
提出日時 2024-07-24 05:45:13
言語 Elixir
(1.18.1)
結果
AC  
実行時間 665 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 62,360 KB
実行使用メモリ 55,200 KB
最終ジャッジ日時 2024-07-24 05:45:29
合計ジャッジ時間 15,475 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def main do
    [g, c, p] = li()
    m = input() |> String.codepoints |> Enum.frequencies

    [bg, bc, bp] = for x <- ["G", "C", "P"], do: Map.get(m, x, 0)
    ans = f(g, c, p, bg, bc, bp)
    IO.puts ans
  end

  def f(ag, ac, ap, bg, bc, bp) do
    g = min(ag, bc)
    c = min(ac, bp)
    p = min(ap, bg)
    if g+c+p == 0 do
      min(ag, bg) + min(ac, bc) + min(ap, bp)
    else
      3 * (g + c + p) + f(ag-g, ac-c, ap-p, bg-p, bc-g, bp-c)
    end
  end

  def input, do: IO.read(:line) |> String.trim
  def ii, do: input() |> String.to_integer
  def li, do: input() |> String.split |> Enum.map(&String.to_integer/1)
end
0