結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,876 KB
testcase_01 AC 44 ms
55,796 KB
testcase_02 AC 43 ms
55,888 KB
testcase_03 AC 41 ms
55,828 KB
testcase_04 AC 40 ms
55,400 KB
testcase_05 AC 40 ms
54,508 KB
testcase_06 AC 40 ms
54,172 KB
testcase_07 AC 41 ms
54,484 KB
testcase_08 AC 72 ms
73,436 KB
testcase_09 AC 64 ms
70,760 KB
testcase_10 AC 74 ms
73,424 KB
testcase_11 AC 70 ms
71,504 KB
testcase_12 AC 71 ms
72,456 KB
testcase_13 AC 591 ms
92,300 KB
testcase_14 AC 598 ms
95,932 KB
testcase_15 AC 580 ms
84,288 KB
testcase_16 AC 585 ms
84,560 KB
testcase_17 AC 583 ms
84,488 KB
testcase_18 AC 84 ms
78,900 KB
testcase_19 AC 86 ms
79,200 KB
testcase_20 AC 86 ms
79,048 KB
testcase_21 AC 581 ms
84,460 KB
testcase_22 AC 582 ms
84,492 KB
testcase_23 AC 580 ms
84,436 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 99 ms
79,100 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 i 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