0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでelixir その352

Last updated at Posted at 2025-11-18

概要

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

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?