1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでelixir その331

Posted at

概要

paiza.ioでelixirやってみた。
AtCoder、やってみた。

参考にしたページ

サンプルコード

abc190_c


defmodule Abc190.C.Main do
  def main() do
    [_n, m] = IO.read(:line) 
        |> String.trim() 
        |> String.split(" ") 
        |> Enum.map(&String.to_integer/1)
    ab_of_lists = 1..m
      |> Enum.reduce([], fn _, acc ->
        list = IO.read(:line) 
            |> String.trim() 
            |> String.split(" ") 
            |> Enum.map(&String.to_integer/1)
        [list | acc]
      end)
    k = IO.read(:line) 
        |> String.trim() 
        |> String.to_integer()
    cd_of_lists = 1..k
      |> Enum.reduce([], fn _, acc ->
        list = IO.read(:line) 
            |> String.trim() 
            |> String.split(" ") 
            |> Enum.map(&String.to_integer/1)
        [list | acc]
      end)
    apply(__MODULE__, :product, cd_of_lists)
    |> Enum.map(fn list ->
      Enum.count(ab_of_lists, fn [a, b] ->
        a in list and b in list
      end)
    end)
    |> Enum.max()
    |> IO.puts()
  end
  def product(l1, l2 \\ [nil, nil], l3 \\ [nil, nil], l4 \\ [nil, nil], l5 \\ [nil, nil], l6 \\ [nil, nil], l7 \\ [nil, nil], l8 \\ [nil, nil],
        l9 \\ [nil, nil], l10 \\ [nil, nil], l11 \\ [nil, nil], l12 \\ [nil, nil], l13 \\ [nil, nil], l14 \\ [nil, nil], l15 \\ [nil, nil], l16 \\ [nil, nil]) do
    for(a <- l1, b <- l2, c <- l3, d <- l4, e <- l5, f <- l6, g <- l7, h <- l8,
      i <- l9, j <- l10, k <- l11, l <- l12, m <- l13, n <- l14, o <- l15, p <- l16,
      uniq: true, do: [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] |> Enum.reject(&is_nil/1))
  end
end

Abc190.C.Main.main()

実行結果

2

成果物

以上。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?