結果

問題 No.1141 田グリッド
ユーザー StrorkisStrorkis
提出日時 2020-07-31 22:56:59
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,354 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 149,788 KB
実行使用メモリ 5,884 KB
最終ジャッジ日時 2023-09-21 01:46:05
合計ジャッジ時間 3,780 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 30 ms
4,380 KB
testcase_14 AC 40 ms
5,884 KB
testcase_15 AC 30 ms
4,380 KB
testcase_16 AC 30 ms
4,380 KB
testcase_17 AC 30 ms
4,380 KB
testcase_18 AC 28 ms
4,376 KB
testcase_19 AC 29 ms
4,380 KB
testcase_20 AC 29 ms
4,380 KB
testcase_21 AC 30 ms
4,376 KB
testcase_22 AC 30 ms
4,376 KB
testcase_23 AC 30 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{BufRead, Write};

const MOD: usize = 1_000_000_007;

fn main () {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let (h, w): (usize, usize) = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let mut a: Vec<Vec<usize>> = Vec::with_capacity(h);
    for _ in 0..h {
        let b: Vec<usize> = {
            let mut buf = String::new();
            reader.read_line(&mut buf).unwrap();
            let iter = buf.split_whitespace();
            iter.map(|x| x.parse().unwrap()).collect()
        };
        a.push(b);
    }

    let pow = |mut a: usize, mut n: usize| -> usize {
        let mut res: usize = 1;
        while n > 0 {
            if (n & 1) > 0 { res = res * a % MOD; }
            a = a * a % MOD;
            n >>= 1;
        }
        res
    };

    let mut res = 1;
    let mut row: Vec<usize> = Vec::with_capacity(h);
    for i in 0..h {
        let mut tmp = 1;
        for j in 0..w {
            tmp = tmp * a[i][j] % MOD;
            res = res * a[i][j] % MOD;
        }
        row.push(tmp);
    }

    let mut column: Vec<usize> = Vec::with_capacity(w);
    for j in 0..w {
        let mut tmp = 1;
        for i in 0..h {
            tmp = tmp * a[i][j] % MOD;
        }
        column.push(tmp);
    }

    let q: usize = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    for _ in 0..q {
        let (r, c): (usize, usize) = {
            let mut buf = String::new();
            reader.read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            (
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            )
        };
    
        let mut ans = res;
        ans = ans * pow(row[r], MOD - 2) % MOD;
        ans = ans * pow(column[c], MOD - 2) % MOD;
        ans = ans * a[r][c] % MOD;
        writeln!(writer, "{}", ans).unwrap();
    }
}
0