結果

問題 No.1141 田グリッド
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-20 14:43:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,472 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 95,816 KB
最終ジャッジ日時 2024-05-01 01:13:13
合計ジャッジ時間 8,966 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,652 KB
testcase_01 AC 43 ms
54,788 KB
testcase_02 AC 42 ms
55,968 KB
testcase_03 AC 44 ms
54,884 KB
testcase_04 AC 43 ms
54,996 KB
testcase_05 AC 43 ms
55,224 KB
testcase_06 AC 41 ms
54,980 KB
testcase_07 AC 43 ms
54,632 KB
testcase_08 AC 79 ms
72,920 KB
testcase_09 AC 66 ms
69,736 KB
testcase_10 AC 73 ms
74,632 KB
testcase_11 AC 69 ms
72,848 KB
testcase_12 AC 70 ms
73,480 KB
testcase_13 AC 579 ms
92,416 KB
testcase_14 AC 594 ms
95,816 KB
testcase_15 AC 578 ms
84,144 KB
testcase_16 AC 574 ms
84,608 KB
testcase_17 AC 582 ms
84,568 KB
testcase_18 AC 88 ms
78,812 KB
testcase_19 AC 89 ms
79,452 KB
testcase_20 AC 85 ms
78,800 KB
testcase_21 AC 581 ms
84,716 KB
testcase_22 AC 584 ms
84,736 KB
testcase_23 AC 608 ms
84,612 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 99 ms
79,412 KB
testcase_30 AC 103 ms
79,072 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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

from collections import defaultdict

flag = False
zr = set()
zc = set()
for i in range(h):
    for j in range(w):
        if A[i][j] == 0:
            flag = True
            zr.add(i)
            zc.add(j)

if not flag:
    X = [[1]*(w+1) for i in range(h+1)]
    for i in range(h):
        for j in range(w):
            X[i+1][j+1] = X[i+1][j]*X[i][j+1]*pow(X[i][j],mod-2,mod)*A[i][j]
            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
        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(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)

else:
    if len(zr) >= 2 and len(zc) >= 2:
        q = int(input())
        for i in range(q):
            r, c = map(int, input().split())
            r, c = r-1, c-1
            print(0)
    elif len(zr) == 1:
        total = 1
        d = defaultdict(lambda: 1)
        for i in range(h):
            for j in range(w):
                if i in zr:
                    continue
                d[j] *= A[i][j]
                d[j] %= mod
                total *= A[i][j]
                total %= mod
        q = int(input())
        for i in range(q):
            r, c = map(int, input().split())
            r, c = r-1, c-1
            if r in zr:
                ans = total*pow(d[c], mod-2, mod)
                print(ans%mod)
            else:
                print(0)
    elif len(zc) == 1:
        total = 1
        d = defaultdict(lambda: 1)
        for i in range(h):
            for j in range(w):
                if j in zc:
                    continue
                d[i] *= A[i][j]
                d[i] %= mod
                total *= A[i][j]
                total %= mod
        q = int(input())
        for i in range(q):
            r, c = map(int, input().split())
            r, c = r-1, c-1
            if c in zc:
                ans = total*pow(d[r], mod-2, mod)
                print(ans%mod)
            else:
                print(0)
0