Powered by AppSignal & Oban Pro

ABC087B - Coins

submit_1.livemd

ABC087B - Coins

問題

https://atcoder.jp/contests/abs/tasks/abc087_b

回答1

defmodule Main do
  def main do
    :stdio
    |> IO.read(:all)
    |> solve()
    |> IO.puts()
  end

  defp split_lines(lines) do
    lines
    |> String.trim()
    |> String.split("\n")
  end

  def solve(input) do
    [num_500, num_100, num_50, total] =
      input
      |> split_lines()
      |> Enum.map(&String.to_integer/1)

    total_50 = total / 50

    for p_500 <- 0..num_500,
        p_100 <- 0..num_100,
        p_50 <- 0..num_50,
        10 * p_500 + 2 * p_100 + p_50 == total_50 do
      {p_500, p_100, p_50}
    end
    |> Enum.count()
  end
end
"""
2
2
2
100
"""
|> Main.solve()
|> then(&(&1 == 2))
"""
5
1
0
150
"""
|> Main.solve()
|> then(&(&1 == 0))
"""
30
40
50
6000
"""
|> Main.solve()
|> then(&(&1 == 213))