結果

問題 No.988 N×Mマス計算(総和)
ユーザー conf8o
提出日時 2020-02-21 16:21:12
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 12,272 ms
コンパイル使用メモリ 384,480 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 07:28:11
合計ジャッジ時間 12,514 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn main() {
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).ok();
    let mut input = input.trim().split("\n");

    let mut line = input.next().unwrap().split_whitespace();
    let n: u128 = line.next().unwrap().parse().unwrap();
    let m: usize = line.next().unwrap().parse().unwrap();
    let k: u128 = line.next().unwrap().parse().unwrap();

    let mut line = input.next().unwrap().split_whitespace();
    let op: &str = line.next().unwrap();
    let b: Vec<u128> = line.map(|c| c.parse().unwrap()).collect();

    let a = input.map(|c| c.trim().parse::<u128>().unwrap());
    
    let base: u128 = a.sum();
    let mut ans: u128 = 0;
    let f: Box<dyn Fn(u128) -> u128> = match op  { 
        "+" => Box::new(|x: u128| base + x * n),
        _ => Box::new(|x: u128| x * base),
    };
    for i in 0..m {
        ans += f(b[i]);
    }

    println!("{}", ans%k);
}
0