結果

問題 No.1012 荷物収集
ユーザー phsplsphspls
提出日時 2022-12-08 12:16:23
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,580 bytes
コンパイル時間 1,140 ms
コンパイル使用メモリ 163,328 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-22 11:22:35
合計ジャッジ時間 8,370 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 155 ms
5,632 KB
testcase_05 AC 154 ms
5,632 KB
testcase_06 AC 153 ms
5,632 KB
testcase_07 AC 155 ms
5,632 KB
testcase_08 AC 161 ms
5,632 KB
testcase_09 AC 157 ms
5,632 KB
testcase_10 AC 157 ms
5,504 KB
testcase_11 AC 155 ms
5,632 KB
testcase_12 AC 155 ms
5,632 KB
testcase_13 AC 155 ms
5,760 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 1 ms
5,376 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 items = (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();

    items.sort();
    let mut summary = (0..n).map(|i| (items[i].0 - x[0]).abs() * items[i].1).sum::<isize>();
    let mut result = vec![0isize; q];
    result[0] = summary;
    let total_weights = items.iter().map(|&(_, w)| w).sum::<isize>();
    let mut lidx = 0usize;
    let mut lweights = 0isize;
    while lidx < n && items[lidx].0 < x[0] {
        lweights += items[lidx].1;
        lidx += 1;
    }
    for i in 1..q {
        let px = x[i-1];
        let cx = x[i];
        let diff = cx - px;
        summary += lweights * diff;
        summary -= (total_weights - lweights) * diff;
        while lidx < n && items[lidx].0 < cx {
            let (x, w) = items[lidx];
            summary += 2 * (cx - x) * w;
            lweights += w;
            lidx += 1;
        }
        result[i] = summary;
    }
    for &v in result.iter() {
        println!("{}", v);
    }
}
0