結果

問題 No.988 N×Mマス計算(総和)
ユーザー iwotiwot
提出日時 2020-06-02 22:01:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 3,517 ms
コンパイル使用メモリ 151,372 KB
実行使用メモリ 8,792 KB
最終ジャッジ日時 2023-09-20 12:25:53
合計ジャッジ時間 2,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 15 ms
7,784 KB
testcase_12 AC 23 ms
8,244 KB
testcase_13 AC 11 ms
5,584 KB
testcase_14 AC 11 ms
5,308 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 18 ms
5,952 KB
testcase_17 AC 22 ms
7,256 KB
testcase_18 AC 14 ms
6,816 KB
testcase_19 AC 21 ms
7,740 KB
testcase_20 AC 28 ms
8,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
}
0