結果

問題 No.1141 田グリッド
ユーザー tonnnura172tonnnura172
提出日時 2020-08-09 19:59:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,054 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-10-05 11:41:20
合計ジャッジ時間 3,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
A = np.array([LIST() for _ in range(H)])
lu = A.tolist()
for i in range(H):
    lu[i] = list(accumulate(lu[i], lambda x, y:x*y%mod))

for i in range(W):
    for j in range(1, H):
        lu[j][i] = (lu[j-1][i]*lu[j][i])%mod

ru = A[:, ::-1].tolist()
for i in range(H):
    ru[i] = list(accumulate(ru[i], lambda x, y:x*y%mod))

for i in range(W):
    for j in range(1, H):
        ru[j][i] = (ru[j-1][i]*ru[j][i])%mod

ld = A[::-1].tolist()
for i in range(H):
    ld[i] = list(accumulate(ld[i], lambda x, y:x*y%mod))

for i in range(W):
    for j in range(1, H):
        ld[j][i] = (ld[j-1][i]*ld[j][i])%mod

rd = A[::-1, ::-1].tolist()
for i in range(H):
    rd[i] = list(accumulate(rd[i], lambda x, y:x*y%mod))
for i in range(W):
    for j in range(1, H):
        rd[j][i] = (rd[j-1][i]*rd[j][i])%mod


Q = INT()

ans = [0]*Q

for i in range(Q):
    r, c = MAP()
    r -= 1
    c -= 1
    tmp = 1
    if r-1 >= 0 and c-1 >= 0:
        tmp *= lu[r-1][c-1]
        tmp %= mod
    if r-1 >= 0 and W-c-2 >= 0:
        tmp *= ru[r-1][W-c-2]
        tmp %= mod
    if H-r-2 >= 0 and c-1 >= 0:
        tmp *= ld[H-r-2][c-1]
        tmp %= mod
    if H-r-2 >= 0 and W-c-2 >= 0:
        tmp *= rd[H-r-2][W-c-2]
        tmp %= mod

    ans[i] = tmp

print(*ans, sep="\n")
0