結果

問題 No.1141 田グリッド
ユーザー uni_pythonuni_python
提出日時 2020-08-30 22:41:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,968 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 86,640 KB
実行使用メモリ 106,240 KB
最終ジャッジ日時 2023-08-09 18:50:01
合計ジャッジ時間 8,749 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,224 KB
testcase_01 AC 71 ms
71,220 KB
testcase_02 AC 69 ms
71,160 KB
testcase_03 AC 70 ms
71,220 KB
testcase_04 AC 72 ms
71,156 KB
testcase_05 AC 70 ms
71,276 KB
testcase_06 AC 70 ms
71,252 KB
testcase_07 AC 70 ms
71,056 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 208 ms
97,436 KB
testcase_14 AC 295 ms
106,240 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


"""
左上,左下,右上,右下の4方向から累積積を持てば良い
"""
def main():
    mod=10**9+7
    H,W=MI()
    A=[]
    A.append([1]*(W+2))
    for i in range(H):
        a=[1]+LI()+[1]
        A.append(a)
    A.append([1]*(W+2))
        
    lu=[[1]*(W+2) for _ in range(H+2)]
    ld=[[1]*(W+2) for _ in range(H+2)]
    ru=[[1]*(W+2) for _ in range(H+2)]
    rd=[[1]*(W+2) for _ in range(H+2)]
    

    
    for i in range(1,H+1):
        for j in range(1,W+1):
            if lu[i-1][j-1]==0:
                lu[i][j]=0
            else:  
                lu[i][j]=((lu[i][j-1]*lu[i-1][j]*A[i][j])//lu[i-1][j-1])%mod
            
    for i in range(H,0,-1):
        for j in range(1,W+1):
            if ld[i+1][j+1]==0:
                ld[i][j]=0
            else:  
                ld[i][j]=((ld[i][j-1]*ld[i+1][j]*A[i][j])//ld[i+1][j-1])%mod
            
    for i in range(1,H+1):
        for j in range(W,0,-1):
            if ru[i-1][j+1]==0:
                ru[i][j]=0
            else:  
                ru[i][j]=((ru[i][j+1]*ru[i-1][j]*A[i][j])//ru[i-1][j+1])%mod
            
    for i in range(H,0,-1):
        for j in range(W,0,-1):
            if rd[i+1][j+1]==0:
                rd[i][j]=0
            else:  
                rd[i][j]=((rd[i][j+1]*rd[i+1][j]*A[i][j])//rd[i+1][j+1])%mod
            
    Q=I()
    for _ in range(Q):
        r,c=MI()
        ans=lu[r-1][c-1] * ru[r-1][c+1] * ld[r+1][c-1] * rd[r+1][c+1]
        print(ans%mod)
        
    # for i in range(H+2):
    #     print(lu[i])
    # print()
    # for i in range(H+2):
    #     print(ru[i])
    # print()
    # for i in range(H+2):
    #     print(ld[i])
    # print()
    # for i in range(H+2):
    #     print(rd[i])
            
            
        
                
    
            


main()
0