結果

問題 No.1972 Modulo Set
ユーザー cutmdocutmdo
提出日時 2022-06-10 23:00:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,085 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 180,384 KB
実行使用メモリ 7,364 KB
最終ジャッジ日時 2024-04-15 08:53:50
合計ジャッジ時間 3,491 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 10 ms
6,940 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 9 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 14 ms
6,940 KB
testcase_16 AC 13 ms
6,940 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 11 ms
6,944 KB
testcase_20 AC 13 ms
6,940 KB
testcase_21 AC 6 ms
6,944 KB
testcase_22 AC 10 ms
6,944 KB
testcase_23 AC 18 ms
7,212 KB
testcase_24 AC 8 ms
6,940 KB
testcase_25 AC 10 ms
6,940 KB
testcase_26 AC 15 ms
6,940 KB
testcase_27 AC 18 ms
7,268 KB
testcase_28 AC 8 ms
6,940 KB
testcase_29 AC 10 ms
6,940 KB
testcase_30 AC 14 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 13 ms
6,944 KB
testcase_33 AC 19 ms
7,360 KB
testcase_34 AC 20 ms
7,364 KB
testcase_35 AC 19 ms
7,364 KB
testcase_36 AC 19 ms
7,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;
use std::io::Write;
/* ----------------------------------------------- */
fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) {
    let n: usize = sc.next();
    let m: usize = sc.next();
    let v: Vec<usize> = sc.next_vec(n);

    let mut map: HashMap<usize, usize> = HashMap::new();
    for x in v {
        let p = map.entry(x % m).or_insert(0);
        *p += 1
    }
    let mut ans: usize = 0;
    for (&x, &val) in &map {
        ans += if x == 0 || (x == m >> 1 && m & 1 == 0) {
            std::cmp::min(1, val)
        } else {
            let val_r = *map.get(&(m - x)).unwrap_or(&0);
            if val > val_r || (val == val_r && x < m - x) {
                val
            } else {
                0
            }
        };
    }
    writeln!(out, "{:?}", ans).ok();
}

/* ----------------------------------------------- */
#[allow(dead_code)]
mod scanner {
    use std::str::FromStr;
    pub struct Scanner<'a> {
        it: std::str::SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a String) -> Scanner<'a> {
            Scanner {
                it: s.split_whitespace(),
            }
        }
        pub fn next<T: FromStr>(&mut self) -> T {
            self.it.next().unwrap().parse::<T>().ok().unwrap()
        }
        pub fn next_bytes(&mut self) -> Vec<u8> {
            self.it.next().unwrap().bytes().collect()
        }
        pub fn next_chars(&mut self) -> Vec<char> {
            self.it.next().unwrap().chars().collect()
        }
        pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
            (0..len).map(|_| self.next()).collect()
        }
    }
}
/* ----------------------------------------------- */
fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut sc = scanner::Scanner::new(&s);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    run(&mut sc, &mut out);
}
/* ----------------------------------------------- */
0