結果

問題 No.1708 Quality of Contest
ユーザー koba-e964koba-e964
提出日時 2021-10-15 21:53:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,984 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 186,424 KB
実行使用メモリ 23,656 KB
最終ジャッジ日時 2023-10-17 20:15:32
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 131 ms
23,656 KB
testcase_10 AC 106 ms
16,392 KB
testcase_11 AC 112 ms
14,376 KB
testcase_12 AC 117 ms
15,548 KB
testcase_13 AC 112 ms
13,464 KB
testcase_14 AC 117 ms
16,168 KB
testcase_15 AC 137 ms
20,232 KB
testcase_16 AC 134 ms
19,852 KB
testcase_17 AC 119 ms
16,936 KB
testcase_18 AC 122 ms
17,212 KB
testcase_19 AC 127 ms
18,460 KB
testcase_20 AC 119 ms
16,752 KB
testcase_21 AC 125 ms
17,508 KB
testcase_22 AC 118 ms
16,256 KB
testcase_23 AC 136 ms
20,044 KB
testcase_24 AC 97 ms
12,124 KB
testcase_25 AC 98 ms
12,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        n: usize, m: usize, x: i64,
        ab: [(i64, usize1); n],
        k: usize,
        c: [usize; k],
    }
    let mut occ = vec![vec![]; m];
    for &(a, b) in &ab {
        occ[b].push(a);
    }
    let mut v: Vec<i64> = vec![];
    for i in 0..m {
        if occ[i].is_empty() { continue; }
        occ[i].sort(); occ[i].reverse();
        occ[i][0] += x;
        v.extend(&occ[i]);
    }
    v.sort(); v.reverse();
    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = acc[i] + v[i];
    }
    let mut tot = 0;
    for c in c {
        tot += acc[c];
    }
    println!("{}", tot);
}
0