結果

問題 No.816 Beautiful tuples
ユーザー wesriverywesrivery
提出日時 2019-06-22 15:51:08
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,317 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 137,312 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-27 02:55:28
合計ジャッジ時間 5,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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) % 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 a = std::cmp::min(a, b);
    let b = std::cmp::max(a, b);

    let min = std::cmp::max(2 * a - b, 1) as usize;
    let max = (a + b) as usize;

    for i in min..=max {
        if i as i64 != a && i as i64 != b {
            if beautiful(a, b, i as i64) {
                println!("{}", i);
                std::process::exit(0);
            }
        }
    }

    println!("-1");

}

fn main() {
    solve();
}
0