結果

問題 No.959 tree and fire
ユーザー gemmaro
提出日時 2020-04-25 13:46:37
言語 Elixir
(1.18.1)
結果
AC  
実行時間 573 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 1,016 ms
コンパイル使用メモリ 63,656 KB
実行使用メモリ 56,144 KB
最終ジャッジ日時 2024-12-31 04:45:02
合計ジャッジ時間 34,353 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def main do
    [n, m] =
      IO.read(:line)
      |> String.trim()
      |> String.split()
      |> Enum.map(&String.to_integer/1)

    p =
      IO.read(:line)
      |> String.trim()
      |> (fn s ->
            case s do
              "0" -> 0
              "1" -> 1
              _ -> s |> String.to_float()
            end
          end).()

    solve({n, m}, p)
    |> IO.puts()
  end

  def solve({n, m}, p) do
    case {n, m} do
      {1, 1} ->
        p

      {1, 2} ->
        2 * :math.pow(p, 2)

      {1, _} ->
        2 * :math.pow(p, 2) + :math.pow(p, 3) * (m - 2)

      {2, 1} ->
        2 * :math.pow(p, 2)

      {_, 1} ->
        2 * :math.pow(p, 2) + :math.pow(p, 3) * (n - 2)

      _ ->
        4 * :math.pow(p, 3) + :math.pow(p, 4) * (2 * n + 2 * m - 8) +
          :math.pow(p, 5) * (n - 2) * (m - 2)
    end
  end
end
0