結果
| 問題 |
No.885 アマリクエリ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-01 00:06:31 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 243 ms / 2,000 ms |
| コード長 | 1,272 bytes |
| コンパイル時間 | 13,012 ms |
| コンパイル使用メモリ | 382,948 KB |
| 実行使用メモリ | 10,580 KB |
| 最終ジャッジ日時 | 2024-10-07 19:36:04 |
| 合計ジャッジ時間 | 16,278 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 mapping = BTreeMap::new();
for &v in a.iter() {
*mapping.entry(v % x[0]).or_insert(0usize) += 1;
}
let mut summary = mapping.iter().map(|(&val, &cnt)| val * cnt).sum::<usize>();
println!("{}", summary);
for &v in x.iter().skip(1) {
let mut stack = vec![];
mapping.range(v..).for_each(|(&val, &cnt)| { stack.push((val, cnt)); });
for &(key, cnt) in stack.iter() {
mapping.remove(&key);
summary -= key * cnt;
*mapping.entry(key % v).or_insert(0usize) += cnt;
summary += (key % v) * cnt;
}
println!("{}", summary);
}
}