結果

問題 No.988 N×Mマス計算(総和)
ユーザー tonyu0
提出日時 2020-04-30 00:35:24
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 12,263 ms
コンパイル使用メモリ 385,028 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 07:43:34
合計ジャッジ時間 13,579 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let op: char = itr.next().unwrap().parse().unwrap();
    let b: Vec<usize> = (0..m)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans = 0;
    if op == '+' {
        for i in 0..n {
            ans = (ans + a[i] * m) % k;
        }
        for i in 0..m {
            ans = (ans + b[i] * n) % k;
        }
    } else {
        let mut sum = 0;
        for i in 0..n {
            sum = (sum + a[i]) % k;
        }
        for i in 0..m {
            ans = (ans + sum * b[i] % k) % k;
        }
    }
    println!("{}", ans);
}
0