結果

問題 No.1972 Modulo Set
ユーザー phsplsphspls
提出日時 2022-09-20 10:53:32
言語 Rust
(1.77.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 12,859 ms
コンパイル使用メモリ 392,144 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-01 16:53:55
合計ジャッジ時間 14,908 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 7 ms
6,940 KB
testcase_06 AC 11 ms
6,944 KB
testcase_07 AC 16 ms
6,940 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 16 ms
6,940 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 19 ms
6,944 KB
testcase_16 AC 21 ms
6,944 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 18 ms
6,944 KB
testcase_20 AC 22 ms
6,944 KB
testcase_21 AC 9 ms
6,944 KB
testcase_22 AC 16 ms
6,944 KB
testcase_23 AC 31 ms
6,940 KB
testcase_24 AC 12 ms
6,944 KB
testcase_25 AC 18 ms
6,940 KB
testcase_26 AC 25 ms
6,944 KB
testcase_27 AC 33 ms
6,940 KB
testcase_28 AC 12 ms
6,944 KB
testcase_29 AC 18 ms
6,940 KB
testcase_30 AC 26 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 23 ms
6,944 KB
testcase_33 AC 37 ms
6,940 KB
testcase_34 AC 37 ms
6,940 KB
testcase_35 AC 38 ms
6,944 KB
testcase_36 AC 37 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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