結果

問題 No.1141 田グリッド
ユーザー brthyyjp
提出日時 2021-03-20 14:18:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 729 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 94,688 KB
最終ジャッジ日時 2024-11-20 23:32:18
合計ジャッジ時間 14,919 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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

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(ans%mod)
0