結果

問題 No.1141 田グリッド
ユーザー ntk-ta01ntk-ta01
提出日時 2020-07-31 23:39:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,689 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 96,276 KB
最終ジャッジ日時 2023-09-21 03:14:17
合計ジャッジ時間 14,549 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,552 KB
testcase_01 AC 74 ms
71,396 KB
testcase_02 AC 74 ms
71,344 KB
testcase_03 AC 74 ms
71,264 KB
testcase_04 AC 74 ms
71,524 KB
testcase_05 AC 75 ms
71,272 KB
testcase_06 AC 72 ms
71,556 KB
testcase_07 AC 74 ms
71,468 KB
testcase_08 AC 116 ms
78,552 KB
testcase_09 AC 109 ms
77,800 KB
testcase_10 AC 114 ms
78,148 KB
testcase_11 AC 113 ms
78,180 KB
testcase_12 AC 124 ms
78,176 KB
testcase_13 AC 424 ms
95,960 KB
testcase_14 AC 487 ms
96,276 KB
testcase_15 AC 410 ms
88,864 KB
testcase_16 AC 406 ms
88,820 KB
testcase_17 AC 411 ms
87,804 KB
testcase_18 AC 540 ms
87,436 KB
testcase_19 AC 561 ms
87,660 KB
testcase_20 AC 549 ms
87,920 KB
testcase_21 AC 400 ms
88,872 KB
testcase_22 AC 402 ms
88,628 KB
testcase_23 AC 401 ms
88,568 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 #

MOD = 10**9 + 7


class modint():
    def __init__(self, value):
        self.value = value % MOD

    def __int__(self):
        return int(self.value)

    def __float__(self):
        return float(self.value)

    def __str__(self):
        return str(self.value)

    def __repr__(self):
        return str(self.value)

    def __add__(self, other):
        return (modint(self.value + other.value) if isinstance(other, modint)
                else modint(self.value + other))

    def __sub__(self, other):
        return (modint(self.value - other.value) if isinstance(other, modint)
                else modint(self.value - other))

    def __mul__(self, other):
        return (modint(self.value * other.value) if isinstance(other, modint)
                else modint(self.value * other))

    def __truediv__(self, other):
        return (modint(self.value * pow(other.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(self.value * pow(other, MOD - 2, MOD)))

    def __pow__(self, other):
        return (modint(pow(self.value, other.value, MOD))
                if isinstance(other, modint)
                else modint(pow(self.value, other, MOD)))

    def __eq__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __ne__(self, other):
        return (self.value != other.value if isinstance(other, modint)
                else self.value != (other % MOD))

    def __radd__(self, other):
        return (modint(other.value + self.value) if isinstance(other, modint)
                else modint(other + self.value))

    def __rsub__(self, other):
        return (modint(other.value - self.value) if isinstance(other, modint)
                else modint(other - self.value))

    def __rmul__(self, other):
        return (modint(other.value * self.value) if isinstance(other, modint)
                else modint(other * self.value))

    def __rtruediv__(self, other):
        return (modint(other.value * pow(self.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(other * pow(self.value, MOD - 2, MOD)))

    def __rpow__(self, other):
        return (modint(pow(other.value, self.value, MOD))
                if isinstance(other, modint)
                else modint(pow(other, self.value, MOD)))

    def modinv(self):
        return modint(pow(self.value, MOD - 2, MOD))


def main():
    H, W = (int(i) for i in input().split())
    A = [[modint(int(i)) for i in input().split()] for j in range(H)]

    pres_h = [1]*(H)
    pres_w = [1]*(W)
    zero_h = []
    zero_w = []
    for h in range(H):
        mul = modint(1)
        for w in range(W):
            if A[h][w] == 0:
                zero_h.append(h)
                break
            else:
                mul *= A[h][w]
        pres_h[h] = mul

    for w in range(W):
        mul = modint(1)
        for h in range(H):
            if A[h][w] == 0:
                zero_w.append(w)
                break
            else:
                mul *= A[h][w]
        pres_w[w] = mul

    zero_h = set(zero_h)
    zero_w = set(zero_w)

    ans = modint(1)
    for h in range(H):
        for w in range(W):
            if h in zero_h or w in zero_w:
                continue
            if A[h][w] != 0:
                ans *= A[h][w]

    Q = int(input())
    for _ in range(Q):
        r, c = (int(i)-1 for i in input().split())
        v = ans / pres_h[r] / pres_w[c] * A[r][c]
        if len(zero_h - {r}) + len(zero_w - {c}) > 0:
            print(0)
        else:
            print(v + MOD)


if __name__ == '__main__':
    main()
0