結果

問題 No.988 N×Mマス計算(総和)
ユーザー evawenisevawenis
提出日時 2021-02-04 02:16:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 5,069 ms
コンパイル使用メモリ 145,948 KB
実行使用メモリ 8,528 KB
最終ジャッジ日時 2023-09-12 21:45:21
合計ジャッジ時間 5,976 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 15 ms
7,800 KB
testcase_12 AC 25 ms
8,136 KB
testcase_13 AC 12 ms
5,424 KB
testcase_14 AC 10 ms
5,360 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 21 ms
5,680 KB
testcase_17 AC 25 ms
6,884 KB
testcase_18 AC 13 ms
6,872 KB
testcase_19 AC 24 ms
7,468 KB
testcase_20 AC 33 ms
8,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let (n, m, k) = get_nmk();
    let (operator, row) = get_row(k);
    let column = get_column(n, k);
    let ans = get_ans(operator, row, column, n, m, k);
    println!("{}", ans);
}

fn add(row: i64, column: i64, n: i64, m: i64, k: i64) -> i64 {
    (row * n + column * m) % k
}

fn mul(row: i64, column: i64, k: i64) -> i64 {
    row * column % k
}

fn get_ans(op: Operator, row: i64, column: i64, n: i64, m: i64, k: i64) -> i64 {
    match op {
        Operator::Add => add(row, column, n, m, k),
        Operator::Mul => mul(row, column, k),
    }
}

fn get_column(n: i64, k: i64) -> i64 {
    (0..n)
        .map(|_| {
            read_line()
                .into_iter()
                .next()
                .unwrap()
                .parse::<i64>()
                .unwrap()
        })
        .sum::<i64>()
        % k
}

fn get_row(k: i64) -> (Operator, i64) {
    let mut iter = read_line().into_iter();
    let op = match iter.next().unwrap() {
        a if a == "+" => Operator::Add,
        _ => Operator::Mul,
    };
    (
        op,
        iter.map(|num| num.parse::<i64>().unwrap()).sum::<i64>() % k,
    )
}

enum Operator {
    Add,
    Mul,
}

fn get_nmk() -> (i64, i64, i64) {
    let mut iter = read_line().into_iter();
    (
        iter.next().unwrap().parse().unwrap(),
        iter.next().unwrap().parse().unwrap(),
        iter.next().unwrap().parse().unwrap(),
    )
}

fn read_line() -> Vec<String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.split_whitespace()
        .map(|e| e.to_string())
        .collect::<Vec<_>>()
}
0