結果

問題 No.1141 田グリッド
ユーザー uni_pythonuni_python
提出日時 2020-08-05 21:47:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 3,060 ms
コンパイル使用メモリ 81,648 KB
実行使用メモリ 86,924 KB
最終ジャッジ日時 2023-10-17 16:18:30
合計ジャッジ時間 11,652 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,532 KB
testcase_01 AC 35 ms
53,532 KB
testcase_02 AC 34 ms
53,532 KB
testcase_03 AC 35 ms
53,532 KB
testcase_04 AC 34 ms
53,532 KB
testcase_05 AC 35 ms
53,532 KB
testcase_06 AC 34 ms
53,532 KB
testcase_07 AC 35 ms
53,532 KB
testcase_08 AC 47 ms
64,324 KB
testcase_09 AC 45 ms
62,272 KB
testcase_10 AC 48 ms
64,324 KB
testcase_11 AC 46 ms
62,272 KB
testcase_12 AC 52 ms
66,360 KB
testcase_13 AC 179 ms
86,924 KB
testcase_14 AC 221 ms
82,944 KB
testcase_15 AC 170 ms
76,912 KB
testcase_16 AC 172 ms
76,884 KB
testcase_17 AC 173 ms
76,912 KB
testcase_18 AC 91 ms
76,896 KB
testcase_19 AC 90 ms
76,828 KB
testcase_20 AC 90 ms
76,828 KB
testcase_21 AC 171 ms
76,988 KB
testcase_22 AC 170 ms
76,984 KB
testcase_23 AC 172 ms
76,988 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=[]
    wzero=[]
    
    for i in range(H):
        for j in range(W):
            if A[i][j]==0:
                hzero.append(i)
                wzero.append(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=0
        if len(hzero)>=2 or len(wzero)>=2:
            ans=0
        elif len(hzero)==1:
            if hzero[0]!=r:
                ans=0
            else:
                ans=calc(r,q)
        elif len(wzero)==1:
            if wzero[0]!=q:
                ans=0
            else:
                ans=calc(r,q)
        else:
            ans=calc(r,q)
        print(ans)
                
    
            


main()
0