結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-14 23:05:09 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,546 bytes |
| コンパイル時間 | 14,180 ms |
| コンパイル使用メモリ | 384,336 KB |
| 実行使用メモリ | 18,892 KB |
| 最終ジャッジ日時 | 2024-11-16 01:23:57 |
| 合計ジャッジ時間 | 33,151 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 TLE * 6 |
ソースコード
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);
}