結果

問題 No.1141 田グリッド
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-23 21:58:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,137 bytes
コンパイル時間 1,429 ms
コンパイル使用メモリ 81,496 KB
実行使用メモリ 87,088 KB
最終ジャッジ日時 2023-10-21 15:19:28
合計ジャッジ時間 4,985 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,464 KB
testcase_01 AC 40 ms
53,464 KB
testcase_02 AC 40 ms
53,464 KB
testcase_03 AC 39 ms
53,464 KB
testcase_04 AC 39 ms
53,464 KB
testcase_05 AC 39 ms
53,464 KB
testcase_06 AC 38 ms
53,464 KB
testcase_07 AC 39 ms
53,464 KB
testcase_08 AC 53 ms
64,228 KB
testcase_09 AC 51 ms
62,180 KB
testcase_10 AC 53 ms
64,232 KB
testcase_11 AC 50 ms
62,180 KB
testcase_12 AC 58 ms
66,332 KB
testcase_13 AC 148 ms
87,088 KB
testcase_14 AC 184 ms
82,496 KB
testcase_15 AC 104 ms
76,640 KB
testcase_16 AC 105 ms
76,632 KB
testcase_17 AC 107 ms
76,784 KB
testcase_18 AC 92 ms
76,724 KB
testcase_19 AC 90 ms
76,592 KB
testcase_20 AC 89 ms
76,596 KB
testcase_21 AC 104 ms
76,644 KB
testcase_22 AC 103 ms
76,680 KB
testcase_23 AC 104 ms
76,684 KB
testcase_24 AC 91 ms
76,684 KB
testcase_25 AC 100 ms
76,944 KB
testcase_26 AC 97 ms
76,816 KB
testcase_27 AC 97 ms
76,876 KB
testcase_28 AC 99 ms
76,792 KB
testcase_29 AC 91 ms
76,852 KB
testcase_30 AC 90 ms
76,712 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

H, W = map(int, input().split())
A = list(list(map(int, input().split())) for _ in range(H))

ALL = 1
row = [1] * H
col = [1] * W
zero = set()
for i, ai in enumerate(A):
    for j, a in enumerate(ai):
        if a == 0:
            zero.add((i, j))
            A[i][j] = 1
        else:
            ALL *= a
            row[i] *= a
            col[j] *= a
            ALL %= mod
            row[i] %= mod
            col[j] %= mod
for i in range(H):
    row[i] = pow(row[i], mod - 2, mod)
for j in range(W):
    col[j] = pow(col[j], mod - 2, mod)


safe = True
R = -1
C = -1
if zero:
    safe = False
    r_safe = [0] * H
    c_safe = [0] * W
    for r, c in zero:
        r_safe[r] = 1
        c_safe[c] = 1
    if sum(r_safe) <= 1:
        R = r_safe.index(1)
    if sum(c_safe) <= 1:
        C = c_safe.index(1)


Q = int(input())
for _ in range(Q):
    r, c = map(int, input().split())
    r -= 1
    c -= 1
    if safe or r == R or c == C:
        res = ALL * row[r] * col[c] * A[r][c] % mod
        print(res)
    else:
        print(0)
0