結果

問題 No.116 門松列(1)
ユーザー gemmaro
提出日時 2020-04-16 19:59:49
言語 Elixir
(1.18.1)
結果
AC  
実行時間 548 ms / 5,000 ms
コード長 496 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 63,104 KB
実行使用メモリ 55,172 KB
最終ジャッジ日時 2024-12-31 04:09:35
合計ジャッジ時間 15,466 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def main do
    IO.read(:line)

    IO.read(:line)
    |> String.split()
    |> Enum.map(&String.to_integer/1)
    |> solve
    |> IO.puts()
  end

  defp solve(h) do
    0..(length(h) - 3)
    |> Enum.map(fn i ->
      [x, y, z] = h |> Enum.slice(i, 3)

      cond do
        (x < z && z < y) ||
          (y < z && z < x) ||
          (z < x && x < y) ||
            (y < x && x < z) ->
          1

        true ->
          0
      end
    end)
    |> Enum.sum()
  end
end
0