結果
問題 | No.1141 田グリッド |
ユーザー | None |
提出日時 | 2021-02-25 12:06:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,698 bytes |
コンパイル時間 | 252 ms |
コンパイル使用メモリ | 81,628 KB |
実行使用メモリ | 89,680 KB |
最終ジャッジ日時 | 2023-10-26 02:38:20 |
合計ジャッジ時間 | 15,675 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,580 KB |
testcase_01 | AC | 38 ms
53,580 KB |
testcase_02 | AC | 37 ms
53,580 KB |
testcase_03 | AC | 36 ms
53,580 KB |
testcase_04 | AC | 37 ms
53,580 KB |
testcase_05 | AC | 37 ms
53,580 KB |
testcase_06 | AC | 37 ms
53,580 KB |
testcase_07 | AC | 38 ms
53,580 KB |
testcase_08 | AC | 59 ms
66,340 KB |
testcase_09 | AC | 54 ms
64,272 KB |
testcase_10 | AC | 58 ms
66,340 KB |
testcase_11 | AC | 57 ms
64,272 KB |
testcase_12 | AC | 64 ms
68,444 KB |
testcase_13 | AC | 507 ms
88,040 KB |
testcase_14 | AC | 551 ms
89,680 KB |
testcase_15 | AC | 494 ms
79,600 KB |
testcase_16 | AC | 492 ms
80,132 KB |
testcase_17 | AC | 497 ms
80,216 KB |
testcase_18 | AC | 493 ms
79,916 KB |
testcase_19 | AC | 497 ms
80,392 KB |
testcase_20 | AC | 491 ms
79,868 KB |
testcase_21 | AC | 498 ms
79,612 KB |
testcase_22 | AC | 490 ms
79,612 KB |
testcase_23 | AC | 493 ms
79,612 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 | - |
ソースコード
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)