結果

問題 No.816 Beautiful tuples
ユーザー wesriverywesrivery
提出日時 2019-06-22 17:06:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 1,500 ms
コード長 1,243 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 134,512 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 02:59:25
合計ジャッジ時間 1,589 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

fn beautiful(a: i64, b: i64, c: i64) -> bool {
    a != b && b != c && c != a && (a + b) % c == 0 && (b + c) % a == 0 && (c + a) % b == 0
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (a, b) = input!(i64, i64);

    let small = std::cmp::min(a, b);
    let big = std::cmp::max(a, b);

    if beautiful(small, big, big - small) {
        println!("{}", big - small);
    } else if beautiful(small, big, small + big) {
        println!("{}", small + big);
    } else {
        println!("-1");
    }

}

fn main() {
    solve();
}
0