Submission #18985752
Source Code Expand
Copy
defmodule Main do def main do [n, k] = IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1) list = 1..n |> Enum.reduce([], fn _, acc -> line = IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1) [line | acc] end) |> Enum.reverse() solve(n, k, list) |> IO.puts() end def solve(n, k, list) do (0..n-1) |> Enum.to_list() |> permutations() |> Enum.filter(fn path -> Enum.at(path, 0) == 0 end) |> Enum.map(fn path -> (0..n-1) |> Enum.reduce(0, fn i, acc -> now_point = Enum.at(path, i) next_point = if i == n - 1 do 0 else Enum.at(path, i + 1) end acc + Enum.at(Enum.at(list, now_point), next_point) end) end) |> Enum.filter(&(&1 == k)) |> Enum.count() end def permutations([]), do: [[]] def permutations(list), do: for elm <- list, rest <- permutations(list -- [elm]), do: [elm | rest] end
Submission Info
Submission Time | |
---|---|
Task | C - Travel |
User | akht |
Language | Elixir (1.10.2) |
Score | 300 |
Code Size | 1030 Byte |
Status | AC |
Exec Time | 483 ms |
Memory | 54580 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt |
All | max_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, sample_01.txt, sample_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
max_01.txt | AC | 466 ms | 54580 KB |
random_01.txt | AC | 403 ms | 32516 KB |
random_02.txt | AC | 393 ms | 30588 KB |
random_03.txt | AC | 403 ms | 32484 KB |
random_04.txt | AC | 419 ms | 30636 KB |
random_05.txt | AC | 483 ms | 54328 KB |
random_06.txt | AC | 399 ms | 30596 KB |
random_07.txt | AC | 417 ms | 30536 KB |
random_08.txt | AC | 398 ms | 30640 KB |
random_09.txt | AC | 395 ms | 30664 KB |
random_10.txt | AC | 400 ms | 32424 KB |
random_11.txt | AC | 384 ms | 30672 KB |
random_12.txt | AC | 404 ms | 32488 KB |
random_13.txt | AC | 403 ms | 30544 KB |
random_14.txt | AC | 392 ms | 30544 KB |
random_15.txt | AC | 384 ms | 30500 KB |
sample_01.txt | AC | 395 ms | 30508 KB |
sample_02.txt | AC | 392 ms | 30512 KB |