結果

問題 No.1120 Strange Teacher
ユーザー phsplsphspls
提出日時 2020-07-23 19:20:00
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,359 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 145,400 KB
実行使用メモリ 5,796 KB
最終ジャッジ日時 2023-09-05 22:30:54
合計ジャッジ時間 2,396 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 12 ms
5,556 KB
testcase_05 AC 11 ms
5,560 KB
testcase_06 AC 11 ms
5,516 KB
testcase_07 AC 11 ms
5,492 KB
testcase_08 AC 11 ms
5,528 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 11 ms
5,596 KB
testcase_11 AC 11 ms
5,600 KB
testcase_12 AC 11 ms
5,596 KB
testcase_13 AC 11 ms
5,532 KB
testcase_14 AC 11 ms
5,488 KB
testcase_15 AC 11 ms
5,488 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 12 ms
5,796 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 10 ms
5,264 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 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>();
    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 {
            let has_irdata = b.iter().zip(a.iter())
                .filter(|ba| (*ba.0 -  *ba.1).abs() % 2 != count % 2)
                .count() > 0;
            let actualcount: isize = b.iter().zip(a.iter())
                .map(|ba| *ba.0 - (*ba.1 - count))
                .map(|i| i / 2)
                .sum()
            ;
            println!("{}", if has_irdata || actualcount != count { -1 } else { count });
        }
    } else {
        println!("-1");
    }
}
0