1
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?

More than 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
atcoderやってみた。

参考にしたページ

問題

image.png

サンプルコード

defmodule Main do
	defp output({x, y, _, _, _, _, _}) do
		if x || y, do: "Yes", else: "No"
	end
	def judge(_, {x, y, a0, b0, [a | as], [b | bs], k}) do
		x1 = judge(x, a, a0, k)
		x2 = judge(y, a, b0, k)
		y1 = judge(x, b, a0, k)
		y2 = judge(y, b, b0, k)
		{x1 || x2, y1 || y2, a, b, as, bs, k}
	end
	defp judge(f, n, n0, k), do: f && abs(n - n0) <= k
	defp solve([1, _], _, _), do: "Yes"
	defp solve([n, k], [ai | as], [bi | bs]) do
		1..n - 1
		|> Enum.reduce({true, true, ai, bi, as, bs, k}, &judge/2)
		|> output()
	end
	defp integer_list(str) do
		str
		|> String.trim()
		|> String.split(" ")
		|> Enum.map(&String.to_integer/1)
	end
	def main do
		nk = IO.read(:line) |> integer_list()
		as = IO.read(:line) |> integer_list()
		bs = IO.read(:line) |> integer_list()
		solve(nk, as, bs) 
		|> IO.puts()
	end
end
Main.main

成果物

以上。

1
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
1
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?