結果

問題 No.1141 田グリッド
ユーザー 👑 KazunKazun
提出日時 2021-03-02 18:48:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 90,992 KB
最終ジャッジ日時 2024-04-14 04:48:05
合計ジャッジ時間 6,423 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,656 KB
testcase_01 AC 36 ms
53,296 KB
testcase_02 AC 36 ms
52,248 KB
testcase_03 AC 36 ms
53,412 KB
testcase_04 AC 36 ms
53,532 KB
testcase_05 AC 37 ms
52,936 KB
testcase_06 AC 37 ms
52,740 KB
testcase_07 AC 36 ms
53,024 KB
testcase_08 AC 50 ms
64,376 KB
testcase_09 AC 47 ms
63,352 KB
testcase_10 AC 50 ms
64,416 KB
testcase_11 AC 48 ms
63,816 KB
testcase_12 AC 54 ms
66,384 KB
testcase_13 AC 151 ms
90,992 KB
testcase_14 AC 205 ms
89,592 KB
testcase_15 AC 145 ms
80,420 KB
testcase_16 AC 147 ms
80,048 KB
testcase_17 AC 147 ms
80,192 KB
testcase_18 AC 86 ms
78,388 KB
testcase_19 AC 87 ms
78,360 KB
testcase_20 AC 87 ms
78,720 KB
testcase_21 AC 146 ms
80,096 KB
testcase_22 AC 144 ms
80,264 KB
testcase_23 AC 143 ms
80,020 KB
testcase_24 AC 88 ms
79,176 KB
testcase_25 AC 91 ms
78,908 KB
testcase_26 AC 92 ms
79,376 KB
testcase_27 AC 91 ms
79,052 KB
testcase_28 AC 91 ms
78,876 KB
testcase_29 AC 93 ms
78,380 KB
testcase_30 AC 87 ms
78,364 KB
testcase_31 AC 89 ms
78,188 KB
testcase_32 AC 85 ms
79,172 KB
testcase_33 AC 86 ms
78,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
write=sys.stdout.write
#============================入力
H,W=map(int,input().split())

A=[[1]*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    A[i][1:]=list(map(int,input().split()))
#============================前計算
Mod=10**9+7

B=[[1]*(W+1) for _ in range(H+1)]
All_prod=1
X_prod=[1]*(H+1)
Y_prod=[1]*(W+1)

Zero_X=[0]*(H+1)
Zero_Y=[0]*(W+1)
for x in range(H+1):
    E=A[x]
    F=B[x]
    for y in range(W+1):
        t=E[y]
        if t==0:
            Zero_X[x]+=1
            Zero_Y[y]+=1
            F[y]=t=1
        else:
            F[y]=t

        All_prod*=t
        All_prod%=Mod

        X_prod[x]*=t
        X_prod[x]%=Mod

        Y_prod[y]*=t
        Y_prod[y]%=Mod
Zero_Total=sum(Zero_X)
#============================クエリ処理
Q=int(input())
T=[0]*Q
for k in range(Q):
    r,c=map(int,input().split())

    zero=Zero_Total-(Zero_X[r]+Zero_Y[c])
    if A[r][c]==0:
        zero+=1

    if zero>0:
        continue

    T[k]=All_prod*pow(X_prod[r]*Y_prod[c],Mod-2,Mod)*B[r][c]
    T[k]%=Mod

write("\n".join(map(str,T)))
0