結果

問題 No.1141 田グリッド
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-20 14:56:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 662 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,972 KB
実行使用メモリ 95,448 KB
最終ジャッジ日時 2024-05-01 01:30:31
合計ジャッジ時間 10,670 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,992 KB
testcase_01 AC 40 ms
53,320 KB
testcase_02 AC 41 ms
54,140 KB
testcase_03 AC 41 ms
52,772 KB
testcase_04 AC 40 ms
53,628 KB
testcase_05 AC 41 ms
54,380 KB
testcase_06 AC 41 ms
53,228 KB
testcase_07 AC 42 ms
52,524 KB
testcase_08 AC 73 ms
71,280 KB
testcase_09 AC 63 ms
67,852 KB
testcase_10 AC 73 ms
71,820 KB
testcase_11 AC 68 ms
69,420 KB
testcase_12 AC 71 ms
71,728 KB
testcase_13 AC 615 ms
92,704 KB
testcase_14 AC 662 ms
95,448 KB
testcase_15 AC 615 ms
84,564 KB
testcase_16 AC 618 ms
85,236 KB
testcase_17 AC 621 ms
85,144 KB
testcase_18 AC 203 ms
81,748 KB
testcase_19 AC 210 ms
82,604 KB
testcase_20 AC 202 ms
81,820 KB
testcase_21 AC 614 ms
84,112 KB
testcase_22 AC 609 ms
84,344 KB
testcase_23 AC 612 ms
84,628 KB
testcase_24 AC 226 ms
82,324 KB
testcase_25 AC 241 ms
82,248 KB
testcase_26 AC 238 ms
82,376 KB
testcase_27 AC 234 ms
83,384 KB
testcase_28 AC 242 ms
82,196 KB
testcase_29 AC 202 ms
81,504 KB
testcase_30 AC 218 ms
81,916 KB
testcase_31 AC 230 ms
82,124 KB
testcase_32 AC 205 ms
82,064 KB
testcase_33 AC 203 ms
81,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]
mod = 1000000007

X = [[1]*(w+1) for i in range(h+1)]
total0 = 0
row0 = [0]*h
col0 = [0]*w
for i in range(h):
    for j in range(w):
        if A[i][j] != 0:
            X[i+1][j+1] = X[i+1][j]*X[i][j+1]*pow(X[i][j],mod-2,mod)*A[i][j]
        else:
            X[i+1][j+1] = X[i+1][j]*X[i][j+1]*pow(X[i][j],mod-2,mod)*1
            total0 += 1
            row0[i] += 1
            col0[j] += 1
        X[i+1][j+1] %= mod

def rect(r1, c1, r2, c2):
    res = X[r2][c2]*pow(X[r2][c1],mod-2, mod)*pow(X[r1][c2],mod-2, mod)*X[r1][c1]
    return res%mod

#print(X)
#print(X[h][w]%mod)

q = int(input())
for i in range(q):
    r, c = map(int, input().split())
    r, c = r-1, c-1
    z = total0-row0[r]-col0[c]
    if A[r][c] == 0:
        z += 1
    if z > 0:
        print(0)
    else:
        ans = rect(r+1, c+1, h, w)*rect(0, c+1, r, w)*rect(r+1, 0, h, c)*rect(0, 0, r, c)
        print(ans%mod)
0