概要
paiza.ioでelixirやってみた。
atcoder、見つけたので、やってみた。
参考にしたページ
サンプルコード
defmodule Main do
def distance({x1, y1}, {x2, y2}) do
abs(x1 - x2) + abs(y1 - y2)
end
def can_travel({x1, y1}, {x2, y2}, t) do
d = distance({x1, y1}, {x2, y2})
d <= t and rem(t - d, 2) == 0
end
def can_travel({t1, x1, y1}, {t2, x2, y2}) do
can_travel({x1, y1}, {x2, y2}, t2 - t1)
end
def proper_plan?([]) do
true
end
def proper_plan?([_]) do
true
end
def proper_plan?([a, b | t]) do
can_travel(a, b) and proper_plan?([b | t])
end
def main do
n = IO.gets("")
|> String.trim()
|> String.to_integer
d = 1..n
|> Enum.map(fn _ ->
IO.gets("")
|> String.trim()
|> String.split(" ")
|> Enum.map(&String.to_integer(&1))
end)
|> Enum.map(fn [t, x, y] ->
{t, x, y}
end)
d = [{0, 0, 0} | d]
if proper_plan?(d) do
IO.puts("Yes")
else
IO.puts("No")
end
end
end
実行結果
Yes
成果物
以上。