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.

wslでelixir その126

Posted at

概要

wsl(wsl2じゃない)で、elixirやってみた。
LivebookでAtCoderやってみた。

写真

image.png

サンプルコード

abc245 c

defmodule Main do
	alias MyIO, as: IO
	def next_token(acc \\ "") do
		case IO.getn(:stdio, "", 1) do
			" " ->
				acc
			"\n" ->
				acc
			x ->
				next_token(acc <> x)
		end
	end
	def input(), do: IO.read(:line) |> String.trim()
	def ii(), do: next_token() |> String.to_integer()
	def li(), do: input() |> String.split(" ") |> Enum.map(&String.to_integer/1)

	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

	def main() do
    nk = li()
		as = li()
		bs = li()
		solve(nk, as, bs)
		|> IO.puts()
	end
end

実行結果

{["5 4\n9 8 3 7 2\n1 6 2 9 5\n", "4 90\n1 1 1 100\n1 2 3 100\n",
  "4 1000000000\n1 1 1000000000 1000000000\n1 1000000000 1 1000000000\n"],
 ["Yes\n", "No\n", "Yes\n"]}
-- TEST 0 --
OK
-- TEST 1 --
OK
-- TEST 2 --
OK

以上。

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?