結果

問題 No.1120 Strange Teacher
ユーザー StrorkisStrorkis
提出日時 2020-07-22 22:51:53
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,417 bytes
コンパイル時間 1,057 ms
コンパイル使用メモリ 146,968 KB
実行使用メモリ 5,076 KB
最終ジャッジ日時 2023-09-05 03:07:26
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 18 ms
4,708 KB
testcase_11 AC 18 ms
4,720 KB
testcase_12 AC 19 ms
4,804 KB
testcase_13 AC 18 ms
4,780 KB
testcase_14 AC 17 ms
4,796 KB
testcase_15 AC 14 ms
4,784 KB
testcase_16 AC 19 ms
4,796 KB
testcase_17 AC 15 ms
4,788 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 13 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let a: Vec<i64> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };
    let b: Vec<i64> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut c = vec![0; n];
    for i in 0..n {
        c[i] = a[i] - b[i];
    }
    c.sort();

    let ans = {
        if n == 2 {
            let x = c[1] - c[0];
            if x % 2 == 0 {
                x / 2
            } else {
                -1
            }
        } else {
            if (2..(n - 1)).fold(true, |acc, i| acc && c[i] == c[i + 1]) {
                let x = c[2] - c[1];
                if x % 2 == 0 {
                    let y = (c[2] + c[1]) / 2 - (c[0] - x / 2);
                    if y % 2 == 0 {
                        x / 2 + y / 2
                    } else {
                        -1
                    }
                } else {
                    -1
                }
            } else {
                -1
            }
        }
    };
    println!("{}", ans);
}
0