結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-25 12:06:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,698 bytes |
| コンパイル時間 | 236 ms |
| コンパイル使用メモリ | 82,288 KB |
| 実行使用メモリ | 89,796 KB |
| 最終ジャッジ日時 | 2024-09-25 10:39:17 |
| 合計ジャッジ時間 | 14,748 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 10 |
ソースコード
class cumsum2D:
def __init__(self, data):
self.N = len(data)
self.data=data
self.M= len(data[0])
self.cum = [[1] * (self.M + 1) for _ in range(self.N + 1)]
for i in range(self.N):
for j in range(self.M):
self.cum[i + 1][j + 1] = self.cum[i][j + 1] * self.cum[i + 1][j] %MOD * pow(self.cum[i][j],MOD-2,MOD) %MOD * data[i][j] %MOD
def get(self, h1, w1, h2, w2):
"""
長方形の領域 [h1,h2)*[w1,w2) の範囲内にインプットされた数字の和を取る
"""
if h1>h2 or w1>w2: return 0
return self.cum[h2][w2] * pow(self.cum[h1][w2],MOD-2,MOD) %MOD * pow(self.cum[h2][w1],MOD-2,MOD) %MOD * self.cum[h1][w1] %MOD
def __str__(self):
res=["input #########################"]
for line in self.data:
res.append(str(line))
res.append("cumsum #########################")
for line in self.cum:
res.append(str(line))
return "\n".join(res)
def example():
global input
example = iter(
"""
3 4
6 8 6 8
3 4 2 9
2 8 6 3
3
3 2
1 2
1 3
"""
.strip().split("\n"))
input = lambda: next(example)
########################################################################################################
import sys
input = sys.stdin.readline
# example()
MOD=10**9+7
H, W = map(int, input().split())
data = []
for h in range(H):
data.append(list(map(int, input().split())))
cum = cumsum2D(data)
Q=int(input())
for _ in range(Q):
h,w=map(int, input().split())
h,w=h-1,w-1
print(cum.get(0,0,h,w)*cum.get(h+1,w+1,H,W)%MOD*cum.get(h+1,0,H,w)%MOD*cum.get(0,w+1,h,W)%MOD)