結果

問題 No.1972 Modulo Set
ユーザー phsplsphspls
提出日時 2022-09-20 10:53:32
言語 Rust
(1.77.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 149,732 KB
実行使用メモリ 6,788 KB
最終ジャッジ日時 2023-08-23 19:31:48
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 16 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 20 ms
4,400 KB
testcase_16 AC 22 ms
4,680 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 22 ms
4,788 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 34 ms
6,056 KB
testcase_24 AC 13 ms
4,380 KB
testcase_25 AC 20 ms
4,376 KB
testcase_26 AC 26 ms
5,112 KB
testcase_27 AC 35 ms
6,112 KB
testcase_28 AC 14 ms
4,376 KB
testcase_29 AC 19 ms
4,376 KB
testcase_30 AC 28 ms
5,196 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 25 ms
4,916 KB
testcase_33 AC 40 ms
6,784 KB
testcase_34 AC 42 ms
6,568 KB
testcase_35 AC 41 ms
6,788 KB
testcase_36 AC 41 ms
6,784 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> 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

warning: 1 warning emitted

ソースコード

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