結果

問題 No.1141 田グリッド
ユーザー 👑 rin204rin204
提出日時 2022-07-05 16:15:03
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 918 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 89,536 KB
最終ジャッジ日時 2023-08-22 04:47:53
合計ジャッジ時間 11,703 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
70,940 KB
testcase_01 AC 73 ms
70,860 KB
testcase_02 AC 73 ms
70,864 KB
testcase_03 AC 74 ms
70,772 KB
testcase_04 AC 73 ms
70,896 KB
testcase_05 AC 72 ms
70,928 KB
testcase_06 AC 72 ms
70,848 KB
testcase_07 AC 72 ms
70,860 KB
testcase_08 AC 133 ms
76,240 KB
testcase_09 AC 89 ms
76,048 KB
testcase_10 AC 96 ms
76,092 KB
testcase_11 AC 89 ms
76,212 KB
testcase_12 AC 101 ms
76,184 KB
testcase_13 AC 313 ms
89,536 KB
testcase_14 AC 360 ms
83,428 KB
testcase_15 AC 293 ms
79,104 KB
testcase_16 AC 295 ms
79,032 KB
testcase_17 AC 302 ms
79,188 KB
testcase_18 AC 253 ms
79,072 KB
testcase_19 AC 248 ms
79,176 KB
testcase_20 AC 249 ms
78,828 KB
testcase_21 AC 288 ms
79,116 KB
testcase_22 AC 286 ms
78,896 KB
testcase_23 AC 295 ms
79,152 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 245 ms
78,744 KB
testcase_30 AC 257 ms
79,096 KB
testcase_31 AC 270 ms
79,224 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]
prod = 1
zero = 0
prod_row = [1] * h
prod_col = [1] * w
zero_row = [1] * h
zero_col = [1] * w
for i in range(h):
    for j in range(w):
        if A[i][j] == 0:
            zero += 1
            zero_row[i] += 1
            zero_col[j] += 1
        else:
            prod *= A[i][j]
            prod_row[i] *= A[i][j]
            prod_col[j] *= A[i][j]
            prod %= MOD
            prod_row[i] %= MOD
            prod_col[j] %= MOD

Q = int(input())
for _ in range(Q):
    r, c = map(int, input().split())
    r -= 1
    c -= 1
    z = zero - zero_row[r] - zero_col[c] + int(A[r][c] == 0)
    if z > 0:
        print(0)
    else:
        ans = prod * pow(prod_row[r] * prod_col[c] % MOD, MOD - 2, MOD) % MOD
        if A[r][c] != 0:
            ans *= A[r][c]
            ans %= MOD
        print(ans)

0