結果

問題 No.133 カードゲーム
ユーザー milanis48663220milanis48663220
提出日時 2019-10-27 14:09:32
言語 Elixir
(1.16.2)
結果
AC  
実行時間 645 ms / 5,000 ms
コード長 1,419 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 54,120 KB
実行使用メモリ 50,240 KB
最終ジャッジ日時 2023-08-29 23:47:10
合計ジャッジ時間 17,288 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 619 ms
49,332 KB
testcase_01 AC 631 ms
49,664 KB
testcase_02 AC 622 ms
49,424 KB
testcase_03 AC 626 ms
49,412 KB
testcase_04 AC 627 ms
50,136 KB
testcase_05 AC 629 ms
50,028 KB
testcase_06 AC 628 ms
50,048 KB
testcase_07 AC 632 ms
49,900 KB
testcase_08 AC 622 ms
49,512 KB
testcase_09 AC 626 ms
50,092 KB
testcase_10 AC 625 ms
50,240 KB
testcase_11 AC 629 ms
50,092 KB
testcase_12 AC 634 ms
50,016 KB
testcase_13 AC 627 ms
49,472 KB
testcase_14 AC 625 ms
49,476 KB
testcase_15 AC 637 ms
50,052 KB
testcase_16 AC 630 ms
49,492 KB
testcase_17 AC 645 ms
49,512 KB
testcase_18 AC 637 ms
49,504 KB
testcase_19 AC 643 ms
49,428 KB
testcase_20 AC 633 ms
49,384 KB
testcase_21 AC 628 ms
49,440 KB
testcase_22 AC 632 ms
50,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: Enum.chunk/2 is deprecated. Use Enum.chunk_every/2 instead
  Main.exs:27: Comb.permutations/3

ソースコード

diff #

defmodule Int do
	def fac(n, m) do
		ans = []
		cond do
			m*m > n -> ans ++ [n]
			rem(n, m) == 0 -> ans ++ [m] ++ (div(n, m) |> fac(m))
			true -> ans ++ fac(n, m+1)
		end
	end
end

defmodule Comb do
	def permutations(n, n_remain, used) do
		ans =
		for x <- 1..n do
			if Enum.at(used, x-1) == false do
				ps = permutations(n, n_remain-1, List.replace_at(used, x-1, true))
				case n_remain <= 1 do
					true -> [x]
					_ -> Enum.map(ps, fn p ->  List.insert_at(p, -1, x) end)
				end
			end
		end
		|> Enum.filter(fn p -> p != nil end)
		|> List.flatten
		case n_remain > 1 do
			true -> Enum.chunk(ans, n_remain)
			_ -> [ans]
		end
	end
end

defmodule Prob do
	def judge(a, b, pa, pb) do
		result =
		for x <- 1..length(a) do
			Enum.at(a, Enum.at(pa, x-1)-1) > Enum.at(b, Enum.at(pb, x-1)-1)
		end
		length(Enum.filter(result, fn r -> r == true end))*2 > length(a)
	end
end

defmodule Main do
	def main do
		n = IO.gets("") |> String.trim() |> String.to_integer
		used =  for _ <- 1..n, do: false
		p = Comb.permutations(n, n, used)
		q = p
		a = IO.gets("") |> String.trim()  |> String.split(" ") |> Enum.map(fn s -> String.to_integer(s) end)
		b = IO.gets("") |> String.trim()  |> String.split(" ") |> Enum.map(fn s -> String.to_integer(s) end)
		result = for pa <- p, pb <- q, do: Prob.judge(a, b, pa, pb)
		ans = length(Enum.filter(result, fn r -> r == true end))/length(result)
		IO.inspect(ans)
	end
end
0