結果
問題 | No.988 N×Mマス計算(総和) |
ユーザー |
|
提出日時 | 2020-06-02 22:01:48 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 992 bytes |
コンパイル時間 | 10,182 ms |
コンパイル使用メモリ | 398,332 KB |
実行使用メモリ | 8,792 KB |
最終ジャッジ日時 | 2024-07-06 07:46:06 |
合計ジャッジ時間 | 11,370 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { let input:Vec<usize> = read_vec(); let n = input[0]; let _m = input[1]; let k = input[2]; let mut op_with_b:Vec<String> = read_vec(); let op_str = op_with_b.remove(0); let b_s:Vec<usize> = op_with_b.iter().map(|v| v.parse().unwrap()).collect(); let a_s:Vec<usize> = (0..n).map(|_i| { read() }).collect(); let mut ans = 0; let mut sum_a = 0; for a in a_s { sum_a = (sum_a + a) % k; } if op_str == "+" { for b in b_s { ans = (ans + n * b + sum_a) % k; } } else { for b in b_s { ans = (ans + b * sum_a) % k; } } println!("{}", ans % k); }