Powered by AppSignal & Oban Pro

ABC130C - Rectangle Cutting

submit_1.livemd

ABC130C - Rectangle Cutting

問題

https://atcoder.jp/contests/abc130/tasks/abc130_c

回答1

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

  defp split_words(words) do
    String.split(words, " ")
  end

  def solve(input) do
    [w, h, x, y] =
      input
      |> String.trim()
      |> split_words()
      |> Enum.map(&String.to_integer/1)

    x = if x > w / 2, do: w - x, else: x
    y = if y > h / 2, do: h - y, else: y

    asp_rec = w / h
    asp_point = if y == 0, do: 0, else: x / y

    {area, eq} =
      cond do
        w == h || {x, y} == {0, 0} || asp_rec == asp_point ->
          {
            w * h / 2,
            if(x == w / 2 && y == h / 2, do: 1, else: 0)
          }

        true ->
          {
            [x * h / 1, y * w / 1] |> Enum.max(),
            if(x * h == y * w, do: 1, else: 0)
          }
      end

    "#{:erlang.float_to_binary(area, decimals: 6)} #{eq}"
  end
end
"""
2 3 1 2
"""
|> Main.solve()
|> then(&(&1 == "3.000000 0"))
"""
2 2 1 1
"""
|> Main.solve()
|> then(&(&1 == "2.000000 1"))