結果

問題 No.1141 田グリッド
ユーザー AEnAEn
提出日時 2022-05-21 17:00:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 88,340 KB
最終ジャッジ日時 2023-10-20 16:25:07
合計ジャッジ時間 7,573 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,540 KB
testcase_01 AC 33 ms
53,540 KB
testcase_02 AC 34 ms
53,540 KB
testcase_03 AC 35 ms
53,540 KB
testcase_04 AC 35 ms
53,540 KB
testcase_05 AC 34 ms
53,540 KB
testcase_06 AC 35 ms
53,540 KB
testcase_07 AC 34 ms
53,540 KB
testcase_08 AC 54 ms
66,612 KB
testcase_09 AC 49 ms
64,484 KB
testcase_10 AC 54 ms
66,612 KB
testcase_11 AC 49 ms
64,484 KB
testcase_12 AC 62 ms
68,620 KB
testcase_13 AC 295 ms
88,340 KB
testcase_14 AC 357 ms
82,672 KB
testcase_15 AC 290 ms
78,256 KB
testcase_16 AC 286 ms
78,228 KB
testcase_17 AC 295 ms
78,304 KB
testcase_18 AC 204 ms
77,932 KB
testcase_19 AC 198 ms
77,072 KB
testcase_20 AC 197 ms
77,920 KB
testcase_21 AC 278 ms
78,036 KB
testcase_22 AC 274 ms
78,036 KB
testcase_23 AC 276 ms
78,244 KB
testcase_24 AC 206 ms
77,948 KB
testcase_25 AC 204 ms
77,868 KB
testcase_26 AC 205 ms
77,848 KB
testcase_27 AC 208 ms
77,952 KB
testcase_28 AC 201 ms
77,824 KB
testcase_29 AC 182 ms
77,692 KB
testcase_30 AC 206 ms
77,788 KB
testcase_31 AC 206 ms
78,156 KB
testcase_32 AC 200 ms
77,720 KB
testcase_33 AC 200 ms
77,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = [list(map(int, input().split())) for  _ in range(H)]
H_n = [1]*H
W_n = [1]*W
H_z = [0]*H
W_z = [0]*W
mod = 10**9+7
al = 1
al_z = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == 0:
            H_z[i] += 1
            W_z[j] += 1
            al_z += 1
        else:
            H_n[i] *= A[i][j]
            W_n[j] *= A[i][j]
            al *= A[i][j]
            H_n[i] %= mod
            W_n[j] %= mod
            al %= mod

Q = int(input())
for i in range(Q):
    r, c = map(int, input().split())
    if H_z[r-1]+W_z[c-1]-(A[r-1][c-1]==0) != al_z:
        print(0)
    else:
        p = 1 if A[r-1][c-1] == 0 else A[r-1][c-1]
        print((al*pow(H_n[r-1], mod-2, mod)*pow(W_n[c-1], mod-2, mod)*p)%mod)
0