結果

問題 No.1120 Strange Teacher
ユーザー phsplsphspls
提出日時 2020-07-23 16:56:02
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,164 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 144,564 KB
実行使用メモリ 5,688 KB
最終ジャッジ日時 2023-09-05 22:25:07
合計ジャッジ時間 2,306 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
4,384 KB
testcase_04 AC 11 ms
5,524 KB
testcase_05 AC 11 ms
5,540 KB
testcase_06 AC 12 ms
5,452 KB
testcase_07 AC 11 ms
5,468 KB
testcase_08 AC 11 ms
5,564 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 11 ms
5,548 KB
testcase_11 AC 11 ms
5,580 KB
testcase_12 AC 11 ms
5,504 KB
testcase_13 AC 11 ms
5,528 KB
testcase_14 AC 11 ms
5,560 KB
testcase_15 AC 12 ms
5,488 KB
testcase_16 AC 12 ms
5,568 KB
testcase_17 AC 12 ms
5,532 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 13 ms
5,688 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 10 ms
5,300 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<isize> = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let diffs: Vec<isize> = b.iter().zip(a.iter())
        .map(|ba| *ba.0 - *ba.1)
        .collect();
    let count: isize = -1isize * diffs.iter().sum::<isize>();
    let diffmax = diffs.iter().max().unwrap();
    let diffmin = diffs.iter().min().unwrap();
    if (n == 2 && count == 0isize) || (n > 2 && count % (n as isize - 2isize) == 0) {
        let count = if n > 2 { count / (n as isize - 2isize) } else { 0isize } ;
        if n == 2 {
            println!("{}", diffs[0].abs());
        } else if diffmin.abs() <= count && diffmax.abs() <= count {
            println!("{}", count);
        } else {
            println!("-1");
        }
    } else {
        println!("-1");
    }
}
0