結果

問題 No.816 Beautiful tuples
ユーザー nao22bnao22b
提出日時 2019-04-19 21:57:21
言語 Elixir
(1.16.2)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 56,156 KB
実行使用メモリ 51,480 KB
最終ジャッジ日時 2023-08-29 23:19:57
合計ジャッジ時間 11,710 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 620 ms
49,824 KB
testcase_01 AC 620 ms
49,176 KB
testcase_02 AC 613 ms
49,752 KB
testcase_03 AC 621 ms
49,264 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 619 ms
49,964 KB
testcase_08 AC 621 ms
49,904 KB
testcase_09 AC 616 ms
50,108 KB
testcase_10 AC 608 ms
49,264 KB
testcase_11 AC 606 ms
49,176 KB
testcase_12 AC 609 ms
49,380 KB
testcase_13 AC 611 ms
49,284 KB
testcase_14 AC 611 ms
51,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

defmodule Main do

    def is_answer(a, b, _) when (a == b), do: false
    def is_answer(a, _, c) when (a == c), do: false
    def is_answer(_, b, c) when (b == c), do: false
    def is_answer(a, b, c) do
        r1 = rem(a + b, c)
        r2 = rem(a + c, b)
        r3 = rem(b + c, a)
        r1 == 0 && r2 == 0 && r3 == 0
    end

    def solve(a, b) do
        r = rem(a + b, 2)
        d2 = div(a + b, 2)
        cond do
            is_answer(a, b, a + b) -> (a + b)
            r == 0 && is_answer(a, b, d2) -> d2
            true -> -1
        end
    end

    def main do
        [a, b] = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer/1)
        solve(a, b) |> IO.puts
    end
end

0