結果

問題 No.1972 Modulo Set
ユーザー phspls
提出日時 2022-09-20 10:53:32
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 14,876 ms
コンパイル使用メモリ 378,492 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-12-22 03:25:13
合計ジャッジ時間 16,043 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> src/main.rs:8:9
  |
8 |     let n = nm[0];
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

ソースコード

diff #

use std::collections::BTreeMap;


fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    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();

    if m == 1 {
        println!("1");
        return;
    }
    let mut mapping = BTreeMap::new();
    for &v in a.iter() {
        *mapping.entry(v%m).or_insert(0usize) += 1;
    }
    let mut result = 0usize;
    for (&key, cnt) in mapping.iter() {
        let other = (m - key) % m;
        if other == key {
            result += 1;
            continue;
        }
        if other < key && mapping.contains_key(&other) {
            continue;
        }
        let othercnt = *mapping.get(&other).unwrap_or(&0usize);
        result += cnt.max(&othercnt);
    }
    println!("{}", result);
}
0