結果

問題 No.1120 Strange Teacher
ユーザー phsplsphspls
提出日時 2020-07-23 19:24:25
言語 Rust
(1.77.0)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 1,392 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 145,568 KB
実行使用メモリ 5,804 KB
最終ジャッジ日時 2023-09-05 22:36:51
合計ジャッジ時間 2,544 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 12 ms
5,584 KB
testcase_05 AC 12 ms
5,504 KB
testcase_06 AC 12 ms
5,568 KB
testcase_07 AC 12 ms
5,528 KB
testcase_08 AC 12 ms
5,600 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 12 ms
5,608 KB
testcase_11 AC 12 ms
5,600 KB
testcase_12 AC 12 ms
5,608 KB
testcase_13 AC 11 ms
5,564 KB
testcase_14 AC 12 ms
5,560 KB
testcase_15 AC 12 ms
5,580 KB
testcase_16 AC 12 ms
5,512 KB
testcase_17 AC 12 ms
5,576 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 13 ms
5,804 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,380 KB
testcase_24 AC 10 ms
5,296 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
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 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.1 - *ba.0).abs() > count || (*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