結果

問題 No.959 tree and fire
ユーザー gemmarogemmaro
提出日時 2020-04-25 13:46:37
言語 Elixir
(1.16.2)
結果
AC  
実行時間 632 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 55,208 KB
実行使用メモリ 50,700 KB
最終ジャッジ日時 2023-08-30 00:42:49
合計ジャッジ時間 39,126 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 621 ms
49,860 KB
testcase_01 AC 619 ms
50,548 KB
testcase_02 AC 617 ms
49,648 KB
testcase_03 AC 616 ms
50,296 KB
testcase_04 AC 611 ms
49,716 KB
testcase_05 AC 615 ms
49,756 KB
testcase_06 AC 615 ms
49,696 KB
testcase_07 AC 621 ms
50,300 KB
testcase_08 AC 623 ms
49,524 KB
testcase_09 AC 616 ms
49,960 KB
testcase_10 AC 615 ms
49,584 KB
testcase_11 AC 627 ms
49,580 KB
testcase_12 AC 630 ms
49,432 KB
testcase_13 AC 626 ms
49,780 KB
testcase_14 AC 632 ms
50,056 KB
testcase_15 AC 622 ms
49,532 KB
testcase_16 AC 619 ms
50,252 KB
testcase_17 AC 620 ms
50,240 KB
testcase_18 AC 624 ms
50,292 KB
testcase_19 AC 618 ms
49,888 KB
testcase_20 AC 630 ms
50,172 KB
testcase_21 AC 612 ms
50,224 KB
testcase_22 AC 617 ms
50,176 KB
testcase_23 AC 610 ms
49,752 KB
testcase_24 AC 616 ms
50,608 KB
testcase_25 AC 622 ms
50,272 KB
testcase_26 AC 620 ms
50,700 KB
testcase_27 AC 615 ms
50,200 KB
testcase_28 AC 613 ms
49,592 KB
testcase_29 AC 617 ms
49,832 KB
testcase_30 AC 624 ms
50,284 KB
testcase_31 AC 621 ms
49,912 KB
testcase_32 AC 630 ms
50,416 KB
testcase_33 AC 612 ms
49,784 KB
testcase_34 AC 624 ms
50,184 KB
testcase_35 AC 611 ms
49,712 KB
testcase_36 AC 627 ms
49,648 KB
testcase_37 AC 617 ms
49,620 KB
testcase_38 AC 611 ms
49,640 KB
testcase_39 AC 612 ms
50,532 KB
testcase_40 AC 619 ms
49,624 KB
testcase_41 AC 622 ms
49,608 KB
testcase_42 AC 624 ms
50,256 KB
testcase_43 AC 631 ms
49,652 KB
testcase_44 AC 623 ms
49,960 KB
testcase_45 AC 621 ms
49,960 KB
testcase_46 AC 624 ms
49,680 KB
testcase_47 AC 617 ms
49,392 KB
testcase_48 AC 626 ms
49,516 KB
testcase_49 AC 621 ms
49,520 KB
testcase_50 AC 613 ms
49,604 KB
testcase_51 AC 623 ms
50,092 KB
testcase_52 AC 618 ms
49,716 KB
testcase_53 AC 626 ms
49,424 KB
testcase_54 AC 620 ms
49,404 KB
testcase_55 AC 620 ms
50,276 KB
testcase_56 AC 626 ms
49,868 KB
権限があれば一括ダウンロードができます

ソースコード

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