結果

問題 No.1141 田グリッド
ユーザー tonyu0tonyu0
提出日時 2020-07-31 23:57:04
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 2,037 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 149,856 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2023-09-21 03:40:55
合計ジャッジ時間 3,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 29 ms
5,832 KB
testcase_14 AC 35 ms
7,848 KB
testcase_15 AC 28 ms
5,220 KB
testcase_16 AC 27 ms
5,212 KB
testcase_17 AC 27 ms
5,268 KB
testcase_18 AC 11 ms
5,000 KB
testcase_19 AC 12 ms
4,968 KB
testcase_20 AC 11 ms
4,984 KB
testcase_21 AC 27 ms
5,268 KB
testcase_22 AC 27 ms
5,264 KB
testcase_23 AC 27 ms
5,260 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::*;
const MOD: u64 = 1_000_000_007;
fn mod_pow(mut x: u64, mut e: u64, m: u64) -> u64 {
    let mut res = 1;
    while e > 0 {
        if e & 1 == 1 {
            res = res * x % m;
        }
        x = x * x % m;
        e >>= 1;
    }
    res
}

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 h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let mut a = vec![vec![0u64; w]; h];
    let mut row = vec![0; h];
    let mut col = vec![0; w];
    let mut ans = 1u64;

    // 0 kazoeru
    let mut all0 = 0;
    let mut row0 = vec![0; h];
    let mut col0 = vec![0; w];
    for i in 0..h {
        for j in 0..w {
            a[i][j] = itr.next().unwrap().parse().unwrap();
            ans = ans * a[i][j] % MOD;
            all0 += if a[i][j] == 0 { 1 } else { 0 };
        }
    }
    for i in 0..h {
        let mut tmp = 1;
        for j in 0..w {
            tmp = tmp * a[i][j] % MOD;
            row0[i] += if a[i][j] == 0 { 1 } else { 0 };
        }
        row[i] = tmp;
    }
    for j in 0..w {
        let mut tmp = 1;
        for i in 0..h {
            tmp = tmp * a[i][j] % MOD;
            col0[j] += if a[i][j] == 0 { 1 } else { 0 };
        }
        col[j] = tmp;
    }

    let mut out = Vec::new();
    let q: usize = itr.next().unwrap().parse().unwrap();
    for _ in 0..q {
        let r: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let c: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let zero = all0 - row0[r] - col0[c] + (a[r][c] == 0) as i32;
        if zero == 0 {
            let now = ans * mod_pow(row[r], MOD - 2, MOD) % MOD * mod_pow(col[c], MOD - 2, MOD)
                % MOD
                * a[r][c]
                % MOD;
            writeln!(out, "{}", now).ok();
        } else {
            writeln!(out, "0").ok();
        }
    }
    stdout().write_all(&out).unwrap();
}
0