結果
| 問題 |
No.240 ナイト散歩
|
| ユーザー |
|
| 提出日時 | 2020-04-22 20:13:50 |
| 言語 | Elixir (1.18.1) |
| 結果 |
AC
|
| 実行時間 | 577 ms / 2,000 ms |
| コード長 | 863 bytes |
| コンパイル時間 | 1,052 ms |
| コンパイル使用メモリ | 62,572 KB |
| 実行使用メモリ | 55,264 KB |
| 最終ジャッジ日時 | 2024-12-31 04:35:39 |
| 合計ジャッジ時間 | 21,695 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
defmodule Main do
def main do
IO.read(:line)
|> String.trim()
|> String.split()
|> Enum.map(&String.to_integer/1)
|> solve
|> IO.puts()
end
def solve([x, y]) do
if {x, y} in locations(), do: "YES", else: "NO"
end
def locations do
locations1 = [{0, 0}] |> search_rec([])
locations2 = locations1 |> search_rec([])
locations3 = locations2 |> search_rec([])
[locations1, locations2, locations3]
|> Enum.concat()
|> Enum.uniq()
end
def search_rec([], result) do
result
end
def search_rec([{x, y} | t], result) do
t
|> search_rec(
result
|> Enum.concat([
{x - 2, y - 1},
{x - 2, y + 1},
{x - 1, y - 2},
{x - 1, y + 2},
{x + 1, y - 2},
{x + 1, y + 2},
{x + 2, y - 1},
{x + 2, y + 1}
])
)
end
end