結果

問題 No.1141 田グリッド
ユーザー buey_tbuey_t
提出日時 2023-03-28 11:27:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 798 ms / 2,000 ms
コード長 2,911 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 115,528 KB
最終ジャッジ日時 2023-10-20 06:41:59
合計ジャッジ時間 17,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
88,240 KB
testcase_01 AC 168 ms
88,236 KB
testcase_02 AC 159 ms
88,240 KB
testcase_03 AC 155 ms
88,240 KB
testcase_04 AC 157 ms
88,240 KB
testcase_05 AC 154 ms
88,244 KB
testcase_06 AC 150 ms
88,240 KB
testcase_07 AC 154 ms
88,240 KB
testcase_08 AC 246 ms
89,884 KB
testcase_09 AC 208 ms
89,808 KB
testcase_10 AC 211 ms
89,800 KB
testcase_11 AC 218 ms
89,888 KB
testcase_12 AC 230 ms
89,888 KB
testcase_13 AC 443 ms
106,236 KB
testcase_14 AC 638 ms
115,528 KB
testcase_15 AC 438 ms
94,096 KB
testcase_16 AC 791 ms
93,872 KB
testcase_17 AC 790 ms
94,868 KB
testcase_18 AC 769 ms
94,188 KB
testcase_19 AC 798 ms
93,072 KB
testcase_20 AC 708 ms
93,868 KB
testcase_21 AC 690 ms
94,448 KB
testcase_22 AC 494 ms
94,452 KB
testcase_23 AC 618 ms
94,320 KB
testcase_24 AC 483 ms
94,312 KB
testcase_25 AC 422 ms
94,344 KB
testcase_26 AC 459 ms
94,260 KB
testcase_27 AC 441 ms
94,560 KB
testcase_28 AC 435 ms
94,432 KB
testcase_29 AC 396 ms
94,372 KB
testcase_30 AC 451 ms
94,700 KB
testcase_31 AC 426 ms
94,452 KB
testcase_32 AC 469 ms
94,456 KB
testcase_33 AC 417 ms
94,460 KB
権限があれば一括ダウンロードができます

ソースコード

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!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    
    '''
    または、か
    
    0が含まれてるパターンがえぐい
    
    二次元を1次元に変えてしまえばセグメントツリーが使えるのかな
    
    だから田なのか
    '''
    
    H,W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    
    acm1 = [[1]*(W+1) for _ in range(H+1)]
    acm2 = [[1]*(W+1) for _ in range(H+1)]
    acm3 = [[1]*(W+1) for _ in range(H+1)]
    acm4 = [[1]*(W+1) for _ in range(H+1)]
    
    for i in range(H):
        for j in range(W):
            acm1[i][j] = A[i][j]
            acm2[i][j] = A[i][j]
            acm3[i][j] = A[i][j]
            acm4[i][j] = A[i][j]
    
    for i in range(H):
        for j in range(W-1):
            acm1[i][j+1] *= acm1[i][j]
            acm1[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
    
    for i in reversed(range(H)):
        for j in range(W-1):
            acm3[i][j+1] *= acm3[i][j]
            acm3[i][j+1] %= mod1
    for j in range(W):
        for i in reversed(range(1,H)):
            acm3[i-1][j] *= acm3[i][j]
            acm3[i-1][j] %= mod1
    
    for i in range(H):
        for j in reversed(range(1,W)):
            acm2[i][j-1] *= acm2[i][j]
            acm2[i][j-1] %= mod1
    for j in reversed(range(W)):
        for i in range(H-1):
            acm2[i+1][j] *= acm2[i][j]
            acm2[i+1][j] %= mod1
    
    for i in reversed(range(H)):
        for j in reversed(range(1,W)):
            acm4[i][j-1] *= acm4[i][j]
            acm4[i][j-1] %= mod1
    for j in reversed(range(W)):
        for i in reversed(range(1,H)):
            acm4[i-1][j] *= acm4[i][j]
            acm4[i-1][j] %= mod1
    
    Q = int(input())
    for _ in range(Q):
        r,c = map(int, input().split())
        
        print(acm1[r-2][c-2]%mod1*acm2[r-2][c]%mod1*acm3[r][c-2]%mod1*acm4[r][c]%mod1)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0