結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー phsplsphspls
提出日時 2020-02-14 23:05:09
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,546 bytes
コンパイル時間 14,534 ms
コンパイル使用メモリ 401,720 KB
実行使用メモリ 12,788 KB
最終ジャッジ日時 2024-04-27 20:09:17
合計ジャッジ時間 17,087 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
12,656 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 0 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut all_data = String::new();
    std::io::stdin().read_to_string(&mut all_data).ok();
    let mut all_data = all_data.trim().split('\n').map(|s| s.trim());
    let nmk: Vec<usize> = all_data.next().unwrap().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n: usize = nmk[0];
    let k: usize = nmk[2];
    let opb: Vec<&str> = all_data.next().unwrap().split_whitespace().collect();
    let mut bval2count: HashMap<usize, usize> = HashMap::new();
    opb.iter().skip(1).map(|s| s.parse::<usize>().unwrap()).for_each(|i| {
        let target = i % k;
        if let Some(x) = bval2count.get_mut(&target) {
            *x += 1;
        } else {
            bval2count.insert(target, 1);
        }
    });
    let op: &str = opb[0];
    let mut aval2count: HashMap<usize, usize> = HashMap::new();
    all_data.take(n).map(|s| s.parse::<usize>().unwrap()).for_each(|i| {
        let target = i % k;
        if let Some(x) = aval2count.get_mut(&target) {
            *x += 1;
        } else {
            aval2count.insert(target, 1);
        }
    });
    let mut result: usize = 0;
    for (aval, acount) in aval2count.iter() {
        for (bval, bcount) in bval2count.iter() {
            let val = match op {
                "+" => (aval + bval) % k,
                "*" => (aval * bval) % k,
                _ => 0
            };
            if val == 0 {
                result += acount * bcount;
            }
        }
    }
    println!("{}", result);
}
0