結果
問題 | No.966 引き算をして門松列(その1) |
ユーザー |
![]() |
提出日時 | 2024-08-14 03:28:03 |
言語 | Elixir (1.18.1) |
結果 |
AC
|
実行時間 | 1,852 ms / 2,000 ms |
コード長 | 971 bytes |
コンパイル時間 | 2,378 ms |
コンパイル使用メモリ | 61,524 KB |
実行使用メモリ | 55,168 KB |
最終ジャッジ日時 | 2024-08-14 03:28:14 |
合計ジャッジ時間 | 10,386 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 |
ソースコード
defmodule Main do def input, do: IO.read(:line) |> String.trim def ii, do: input() |> String.to_integer def li, do: input() |> String.split |> Enum.map(&String.to_integer/1) def yn(b), do: IO.puts(if b, do: "Yes", else: "No") @inf 10 ** 9 def main do t = ii() for _ <- 1..t do [a, b, c] = li() solve(a, b, c) |> IO.puts end end def solve(a, b, c) do for {a, b, c} <- [{b, a, c}, {b, c, a}, {a, c, b}, {c, a, b}] do f(a, b, c) end |> Enum.min |> then(fn x -> if x >= @inf, do: -1, else: x end) end def f(1, _, _), do: @inf def f(_, 1, _), do: @inf def f(a, b, c) do cond do a <= b -> x = b - a + 1 f(a, b-x, c) + x b <= c -> x = c - b + 1 f(a, b, c-x) + x true -> 0 end end def is_kadomatu(a, b, c) do if a == b or b == c or c == a do false else [_, x, _] = Enum.sort([a, b, c]) b != x end end end