結果

問題 No.1012 荷物収集
ユーザー phsplsphspls
提出日時 2022-11-26 01:43:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,918 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 174,952 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-10 05:56:54
合計ジャッジ時間 8,919 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 144 ms
7,168 KB
testcase_05 AC 144 ms
7,168 KB
testcase_06 AC 148 ms
7,168 KB
testcase_07 AC 148 ms
7,168 KB
testcase_08 AC 147 ms
7,168 KB
testcase_09 AC 141 ms
7,296 KB
testcase_10 AC 145 ms
7,168 KB
testcase_11 AC 148 ms
7,168 KB
testcase_12 AC 149 ms
7,168 KB
testcase_13 AC 149 ms
7,168 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 125 ms
6,944 KB
testcase_25 AC 146 ms
6,940 KB
testcase_26 AC 54 ms
6,940 KB
testcase_27 AC 12 ms
6,944 KB
testcase_28 AC 131 ms
6,944 KB
testcase_29 AC 36 ms
6,940 KB
testcase_30 AC 123 ms
6,944 KB
testcase_31 AC 92 ms
6,940 KB
testcase_32 AC 55 ms
6,944 KB
testcase_33 AC 101 ms
6,944 KB
testcase_34 AC 114 ms
6,940 KB
testcase_35 AC 109 ms
6,940 KB
testcase_36 AC 121 ms
6,940 KB
testcase_37 AC 40 ms
6,940 KB
testcase_38 AC 121 ms
6,944 KB
testcase_39 AC 47 ms
6,940 KB
testcase_40 AC 65 ms
6,940 KB
testcase_41 AC 158 ms
6,944 KB
testcase_42 AC 84 ms
6,940 KB
testcase_43 AC 93 ms
6,944 KB
testcase_44 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut nq = String::new();
    std::io::stdin().read_line(&mut nq).ok();
    let nq: Vec<usize> = nq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nq[0];
    let q = nq[1];
    let mut carries = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<isize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            (temp[0], temp[1])
        })
        .collect::<Vec<_>>();
    let mut x = String::new();
    std::io::stdin().read_line(&mut x).ok();
    let x: Vec<isize> = x.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    carries.sort();
    let mut x = (0..q).map(|i| (x[i], i)).collect::<Vec<_>>();
    x.sort();
    let total_weight = carries.iter().map(|&(_, w)| w).sum::<isize>();
    let mut lidx = 0usize;
    let mut lweights = 0isize;
    let mut result = vec![0; q];
    let mut summary = (0..n).map(|i| carries[i].1 * (carries[i].0 - x[0].0).abs()).sum::<isize>();
    result[x[0].1] = summary;
    while lidx < n && carries[lidx].0 < x[0].0 {
        lweights += carries[lidx].1;
        lidx += 1;
    }
    for i in 1..q {
        let (pxpos, _) = x[i-1];
        let (xpos, qidx) = x[i];
        let diff = xpos - pxpos;
        let mut stack = vec![];
        let mut mweights = 0isize;
        while lidx < n && carries[lidx].0 < xpos {
            stack.push(carries[lidx]);
            mweights += carries[lidx].1;
            lidx += 1;
        }
        summary += diff * lweights;
        summary -= diff * (total_weight - lweights - mweights);
        for &(cx, cw) in stack.iter() {
            summary += (xpos - cx) * cw;
            summary -= (cx - pxpos) * cw;
        }
        lweights += mweights;
        result[qidx] = summary;
    }
    for &v in result.iter() {
        println!("{}", v);
    }
}
0