結果

問題 No.1141 田グリッド
ユーザー buey_tbuey_t
提出日時 2023-03-28 10:29:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,260 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 265,192 KB
最終ジャッジ日時 2023-10-20 05:55:31
合計ジャッジ時間 7,011 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
88,552 KB
testcase_01 AC 126 ms
84,184 KB
testcase_02 AC 126 ms
84,180 KB
testcase_03 AC 125 ms
84,184 KB
testcase_04 AC 125 ms
84,184 KB
testcase_05 AC 125 ms
84,184 KB
testcase_06 AC 125 ms
84,180 KB
testcase_07 AC 126 ms
84,180 KB
testcase_08 AC 197 ms
89,312 KB
testcase_09 AC 174 ms
89,304 KB
testcase_10 AC 199 ms
89,308 KB
testcase_11 AC 221 ms
89,500 KB
testcase_12 AC 203 ms
89,316 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
    from heapq import heapify, heappop, heappush
    from bisect import bisect_left, bisect_right
    from copy import deepcopy
    import copy
    import random
    from collections import deque,Counter,defaultdict
    from itertools import permutations,combinations
    from decimal import Decimal,ROUND_HALF_UP
    #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    from functools import lru_cache, reduce
    #@lru_cache(maxsize=None)
    from operator import add,sub,mul,xor,and_,or_,itemgetter
    INF = 10**18
    mod1 = 10**9+7
    mod2 = 998244353
    
    #DecimalならPython
    #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    def modinv(a, b):
        p = b
        x, y, u, v = 1, 0, 0, 1
        while b:
            k = a // b
            x -= k * u
            y -= k * v
            x, u = u, x
            y, v = v, y
            a, b = b, a % b
        x %= p
        if x < 0:
            x += p
        return x
    
    '''
    または、か
    
    
    '''
    
    H,W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    
    acm1 = [[1]*(W) for _ in range(H)]
    acm2 = [[1]*(W) for _ in range(H)]
    
    sm = 1
    for i in range(H):
        for j in range(W):
            sm *= A[i][j]
            acm1[i][j] = A[i][j]
            acm2[i][j] = A[i][j]
    
    for i in range(H):
        for j in range(W-1):
            acm2[i][j+1] *= acm2[i][j]
            acm2[i][j+1] %= mod1
    
    for j in range(W):
        for i in range(H-1):
            acm1[i+1][j] *= acm1[i][j]
            acm1[i+1][j] %= mod1
    
    gyou = [0]*(H)
    for i in range(H):
        gyou[i] = modinv(acm2[i][W-1],mod1)
    retu = [0]*W
    for i in range(W):
        retu[i] = modinv(acm1[H-1][i],mod1)
    
    Q = int(input())
    for _ in range(Q):
        r,c = map(int, input().split())
        
        print(sm*gyou[r-1]%mod1*retu[c-1]%mod1*A[r-1][c-1]%mod1)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0