結果

問題 No.1120 Strange Teacher
ユーザー StrorkisStrorkis
提出日時 2020-07-22 23:26:41
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,079 bytes
コンパイル時間 5,302 ms
コンパイル使用メモリ 137,016 KB
実行使用メモリ 5,008 KB
最終ジャッジ日時 2023-09-05 04:42:24
合計ジャッジ時間 7,325 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 18 ms
4,756 KB
testcase_05 AC 17 ms
4,656 KB
testcase_06 AC 14 ms
5,008 KB
testcase_07 AC 15 ms
4,736 KB
testcase_08 AC 14 ms
4,768 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 18 ms
4,732 KB
testcase_11 AC 18 ms
4,760 KB
testcase_12 AC 18 ms
4,720 KB
testcase_13 AC 19 ms
4,736 KB
testcase_14 AC 18 ms
4,748 KB
testcase_15 AC 15 ms
4,740 KB
testcase_16 AC 19 ms
4,760 KB
testcase_17 AC 15 ms
4,764 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 12 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 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 mut sum = 0;
    for i in (0..(n - 1)).rev() {
        c[i] -= sum;
        let x = c[i + 1] - c[i];
        if x % 2 == 0 {
            c[i] = (c[i] + c[i + 1]) / 2;
            sum += x / 2;
        } else {
            println!("-1");
            return;
        }
    }

    if c[0] == 0 {
        println!("{}", sum);
    } else {
        println!("-1");
    }
}
0