結果
問題 |
No.1141 田グリッド
|
ユーザー |
|
提出日時 | 2023-07-15 09:41:33 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,365 ms / 2,000 ms |
コード長 | 920 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 76,060 KB |
最終ジャッジ日時 | 2024-09-16 17:57:25 |
合計ジャッジ時間 | 35,368 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
import numpy as np MOD = 1000000007 mul = np.frompyfunc(lambda x, y: x * y % MOD, 2, 1) int1 = lambda x: int(x) - 1 H, W = map(int, input().split()) A = np.array([tuple(map(int, input().split())) for _ in range(H)], dtype=object) Au = mul.accumulate(A, axis=0) Ad = np.flipud(mul.accumulate(np.flipud(A), axis=0)) Aul = mul.accumulate(Au, axis=1).tolist() Aur = np.fliplr(mul.accumulate(np.fliplr(Au), axis=1)).tolist() Adl = mul.accumulate(Ad, axis=1).tolist() Adr = np.fliplr(mul.accumulate(np.fliplr(Ad), axis=1)).tolist() Q = int(input()) for _ in range(Q): ans = 1 r, c = map(int1, input().split()) if 0 < r and 0 < c: ans = ans * Aul[r - 1][c - 1] % MOD if 0 < r and c < W - 1: ans = ans * Aur[r - 1][c + 1] % MOD if r < H - 1 and 0 < c: ans = ans * Adl[r + 1][c - 1] % MOD if r < H - 1 and c < W - 1: ans = ans * Adr[r + 1][c + 1] % MOD print(ans)