結果
問題 | No.885 アマリクエリ |
ユーザー |
|
提出日時 | 2022-12-13 09:44:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 1,180 bytes |
コンパイル時間 | 14,481 ms |
コンパイル使用メモリ | 377,940 KB |
実行使用メモリ | 10,976 KB |
最終ジャッジ日時 | 2024-11-07 05:37:30 |
合計ジャッジ時間 | 18,481 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:7:9 | 7 | let n: usize = n.trim().parse().unwrap(); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `q` --> src/main.rs:13:9 | 13 | let q: usize = q.trim().parse().unwrap(); | ^ help: if this is intentional, prefix it with an underscore: `_q`
ソースコード
use std::collections::BTreeMap; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut q = String::new(); std::io::stdin().read_line(&mut q).ok(); let q: usize = q.trim().parse().unwrap(); let mut x = String::new(); std::io::stdin().read_line(&mut x).ok(); let x: Vec<usize> = x.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut summary = a.iter().sum::<usize>(); let mut btree = BTreeMap::new(); for &v in a.iter() { *btree.entry(v).or_insert(0usize) += 1; } for &x in x.iter() { let targets = btree.range(x..).map(|(&k, &v)| (k, v)).collect::<Vec<_>>(); for &(val, cnt) in targets.iter() { summary -= val * cnt; let nval = val % x; summary += nval * cnt; btree.remove(&val); *btree.entry(nval).or_insert(0usize) += cnt; } println!("{}", summary); } }