結果

問題 No.178 美しいWhitespace (1)
ユーザー tonyu0
提出日時 2020-04-19 17:03:17
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 14,993 ms
コンパイル使用メモリ 386,036 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-05 18:38:26
合計ジャッジ時間 11,966 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| {
            itr.next().unwrap().parse::<usize>().unwrap()
                + itr.next().unwrap().parse::<usize>().unwrap() * 4
        })
        .collect();
    let max = a.iter().max().unwrap();
    let mut ans = 0;
    for i in 0..n {
        if a[i] & 1 != max & 1 {
            println!("-1");
            return;
        }
        ans += (max - a[i]) >> 1;
    }
    println!("{}", ans);
}
0