結果

問題 No.1060 素敵な宝箱
ユーザー noshi91noshi91
提出日時 2020-05-22 23:08:34
言語 Rust
(1.72.1)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,620 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 152,360 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-28 09:29:37
合計ジャッジ時間 2,330 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

use std::io::{self, Read as _, Write as _};

struct Scanner<'a>(std::str::SplitWhitespace<'a>);

impl<'a> Scanner<'a> {
    fn new(s: &'a str) -> Self {
        Self(s.split_whitespace())
    }

    fn next<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let s = self.0.next().expect("found EOF");
        match s.parse() {
            Ok(v) => v,
            Err(msg) => {
                println!(
                    "parse error. T = {}, s = \"{}\": {:?}",
                    std::any::type_name::<T>(),
                    s,
                    msg
                );
                panic!()
            }
        }
    }
}

fn main() {
    let mut stdin = String::new();
    std::io::stdin().read_to_string(&mut stdin).unwrap();
    let mut sc = Scanner::new(&stdin);
    let stdout = io::stdout();
    let mut stdout = io::BufWriter::new(stdout.lock());

    let n = sc.next();
    let m = sc.next();

    let a: Vec<Vec<i64>> = (0..n)
        .map(|_| (0..m).map(|_| sc.next()).collect())
        .collect();

    let coef: Vec<i64> = (0..m).map(|j| a.iter().map(|a| a[j]).sum()).collect();

    let mut b: Vec<i64> = (0..n)
        .map(|i| {
            coef.iter()
                .zip(&a[i])
                .map(|(&c, &a): (&i64, &i64)| c * a)
                .sum()
        })
        .collect();

    b.sort();
    b.reverse();

    let mut ans = 0;

    for i in 0..n {
        match i % 2 {
            0 => ans += b[i],
            _ => ans -= b[i],
        }
    }

    writeln!(stdout, "{}", ans).unwrap();

    stdout.flush().unwrap();
}
0