結果

問題 No.26 シャッフルゲーム
ユーザー gemmarogemmaro
提出日時 2020-04-13 23:16:12
言語 Elixir
(1.16.2)
結果
AC  
実行時間 650 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 1,138 ms
コンパイル使用メモリ 55,452 KB
実行使用メモリ 50,124 KB
最終ジャッジ日時 2023-08-30 00:09:44
合計ジャッジ時間 8,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 638 ms
49,172 KB
testcase_01 AC 642 ms
49,096 KB
testcase_02 AC 650 ms
49,844 KB
testcase_03 AC 648 ms
49,304 KB
testcase_04 AC 643 ms
49,668 KB
testcase_05 AC 639 ms
49,284 KB
testcase_06 AC 644 ms
49,336 KB
testcase_07 AC 635 ms
50,124 KB
testcase_08 AC 637 ms
49,960 KB
testcase_09 AC 633 ms
49,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do
  def main do
    n =
      IO.read(:line)
      |> String.trim()
      |> String.to_integer()

    IO.read(:line)
    |> String.trim()
    |> String.to_integer()
    |> (&(1..&1)).()
    |> Enum.map(fn _ ->
      IO.read(:line)
      |> String.split()
      |> Enum.map(&String.to_integer/1)
    end)
    |> solve(n)
    |> IO.puts()
  end

  defp solve(pq, n) do
    cond do
      Enum.empty?(pq) ->
        n

      true ->
        [p, q] = hd(pq)

        Enum.slice(pq, 1..-1)
        |> solve(
          cond do
            p == n -> q
            q == n -> p
            true -> n
          end
        )
    end
  end
end
0