結果

問題 No.1120 Strange Teacher
ユーザー ikdikd
提出日時 2020-07-22 22:23:49
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,114 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 151,092 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-04 21:31:04
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::Read;

fn read<T: std::str::FromStr>() -> T {
    let token: String = std::io::stdin()
        .bytes()
        .map(|c| c.ok().unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i32 = read();
    let a: Vec<i32> = (0..n).map(|_| read()).collect();
    let b: Vec<i32> = (0..n).map(|_| read()).collect();
    let d = a.iter().sum::<i32>() - b.iter().sum::<i32>();
    if n == 2 {
        if d == 0 {
            println!("{}", (a[0] - b[0]).abs());
        } else {
            println!("-1");
        }
        return;
    }
    if d < 0 || d % (n - 2) != 0 {
        println!("-1");
        return;
    }
    let k = d / (n - 2);
    let a2: Vec<i32> = a.iter().map(|x| x - k).collect();
    let mut m = 0;
    for (a, b) in a2.iter().zip(b.iter()) {
        if a > b || (b - a) % 2 != 0 {
            println!("-1");
            return;
        }
        m += (b - a) / 2;
    }
    if m <= k {
        println!("{}", k);
    } else {
        println!("-1");
    }
}
0