結果

問題 No.1141 田グリッド
ユーザー uni_pythonuni_python
提出日時 2020-08-05 21:57:02
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,302 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 81,728 KB
実行使用メモリ 89,088 KB
最終ジャッジ日時 2023-10-17 17:38:19
合計ジャッジ時間 9,036 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,500 KB
testcase_01 AC 35 ms
53,500 KB
testcase_02 AC 35 ms
53,500 KB
testcase_03 AC 36 ms
53,500 KB
testcase_04 AC 36 ms
53,500 KB
testcase_05 AC 37 ms
53,500 KB
testcase_06 AC 36 ms
53,500 KB
testcase_07 AC 36 ms
53,500 KB
testcase_08 AC 49 ms
64,280 KB
testcase_09 AC 47 ms
62,228 KB
testcase_10 AC 49 ms
64,280 KB
testcase_11 AC 48 ms
62,352 KB
testcase_12 AC 54 ms
66,320 KB
testcase_13 AC 189 ms
86,816 KB
testcase_14 AC 233 ms
82,916 KB
testcase_15 AC 180 ms
76,960 KB
testcase_16 AC 181 ms
76,928 KB
testcase_17 AC 190 ms
76,944 KB
testcase_18 AC 232 ms
78,208 KB
testcase_19 AC 243 ms
78,120 KB
testcase_20 AC 231 ms
78,140 KB
testcase_21 AC 179 ms
76,996 KB
testcase_22 AC 177 ms
77,004 KB
testcase_23 AC 180 ms
76,992 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W=MI()
    A=[]
    for i in range(H):
        a=LI()
        A.append(a)
        
    #0以外の積を計算
    hm=[1]*H
    wm=[1]*W
    M=1
    
    # 2行以上 or 2列以上に0があれば,何をしても答えは0
    hzero=set([])
    wzero=set([])
    
    for i in range(H):
        for j in range(W):
            if A[i][j]==0:
                hzero.add(i)
                wzero.add(j)
            else:
                hm[i]=(hm[i]*A[i][j])%mod
                wm[j]=(wm[j]*A[i][j])%mod
                
                
    for i in range(H):
        M=(M*hm[i])%mod
        
    def calc(r,q):
        res=M
        res=(res*pow(hm[r],mod-2,mod))%mod
        res=(res*pow(wm[q],mod-2,mod))%mod
        res=(res*A[r][q])%mod
        return res

        
    Q=I()
    for _ in range(Q):
        r,q=MI()
        r-=1
        q-=1
        ans=1
        hzero2=hzero - set([r])
        wzero2=wzero - set([q])
        
        if len(hzero2)==0 and len(wzero2)==0:
            ans=calc(r,q)
        else:
            ans=0
        

        print(ans)
                
    
            


main()
0