結果

問題 No.1141 田グリッド
ユーザー rlangevin
提出日時 2024-01-08 12:41:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 101,744 KB
最終ジャッジ日時 2024-09-27 19:35:35
合計ジャッジ時間 6,070 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
mod = 10**9 + 7

class Accumulate2D:
    def __init__(self, A):
        self.H = len(A)
        self.W = len(A[0])
        self.Ac = [[1] * (self.W + 1) for _ in range(self.H + 1)]
        for i in range(1, self.H + 1):
            now = 1
            for j in range(1, self.W + 1):
                now *= A[i-1][j-1]
                now %= mod
                self.Ac[i][j] = self.Ac[i - 1][j] * now
                self.Ac[i][j] %= mod

    def calc_prod(self, C, D):
        return self.Ac[C][D]

def rot90(A):
    # 時計回りに90度回転
    return list(zip(*(A[::-1])))

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
    
G1 = Accumulate2D(A)
A = rot90(A)
G2 = Accumulate2D(A)
A = rot90(A)
G3 = Accumulate2D(A)
A = rot90(A)
G4 = Accumulate2D(A)

Q = int(input())
for _ in range(Q):
    h, w = map(int, input().split())
    h, w = h - 1, w - 1
    ans = G1.calc_prod(h, w)*G2.calc_prod(w, H-h-1)*G3.calc_prod(H-h-1,W-w-1)*G4.calc_prod(W-w-1,h)
    print(ans%mod)
0