結果

問題 No.240 ナイト散歩
ユーザー gemmarogemmaro
提出日時 2020-04-22 20:13:50
言語 Elixir
(1.16.2)
結果
AC  
実行時間 626 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 55,620 KB
実行使用メモリ 51,244 KB
最終ジャッジ日時 2023-08-30 00:36:26
合計ジャッジ時間 24,984 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 620 ms
49,268 KB
testcase_01 AC 619 ms
49,340 KB
testcase_02 AC 615 ms
49,320 KB
testcase_03 AC 615 ms
50,288 KB
testcase_04 AC 613 ms
49,292 KB
testcase_05 AC 604 ms
49,780 KB
testcase_06 AC 605 ms
49,820 KB
testcase_07 AC 609 ms
49,288 KB
testcase_08 AC 606 ms
49,516 KB
testcase_09 AC 616 ms
49,880 KB
testcase_10 AC 611 ms
49,424 KB
testcase_11 AC 611 ms
49,428 KB
testcase_12 AC 618 ms
49,240 KB
testcase_13 AC 616 ms
49,940 KB
testcase_14 AC 626 ms
49,328 KB
testcase_15 AC 621 ms
49,316 KB
testcase_16 AC 610 ms
49,844 KB
testcase_17 AC 607 ms
50,112 KB
testcase_18 AC 599 ms
49,208 KB
testcase_19 AC 607 ms
49,892 KB
testcase_20 AC 597 ms
49,144 KB
testcase_21 AC 615 ms
50,008 KB
testcase_22 AC 611 ms
49,204 KB
testcase_23 AC 606 ms
49,440 KB
testcase_24 AC 604 ms
49,316 KB
testcase_25 AC 604 ms
49,228 KB
testcase_26 AC 598 ms
49,980 KB
testcase_27 AC 607 ms
49,368 KB
testcase_28 AC 600 ms
49,432 KB
testcase_29 AC 609 ms
49,316 KB
testcase_30 AC 606 ms
50,148 KB
testcase_31 AC 606 ms
49,304 KB
testcase_32 AC 600 ms
51,244 KB
testcase_33 AC 617 ms
49,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0