結果

問題 No.1141 田グリッド
ユーザー buey_tbuey_t
提出日時 2023-03-28 12:15:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,086 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,736 KB
実行使用メモリ 101,876 KB
最終ジャッジ日時 2023-10-20 07:19:01
合計ジャッジ時間 10,651 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
84,180 KB
testcase_01 AC 119 ms
84,172 KB
testcase_02 AC 120 ms
84,176 KB
testcase_03 AC 128 ms
84,176 KB
testcase_04 AC 123 ms
84,176 KB
testcase_05 AC 127 ms
84,180 KB
testcase_06 AC 128 ms
84,172 KB
testcase_07 AC 120 ms
84,180 KB
testcase_08 AC 149 ms
89,156 KB
testcase_09 AC 146 ms
89,136 KB
testcase_10 AC 150 ms
89,152 KB
testcase_11 AC 144 ms
89,140 KB
testcase_12 AC 162 ms
89,208 KB
testcase_13 AC 342 ms
101,876 KB
testcase_14 AC 404 ms
95,740 KB
testcase_15 AC 348 ms
90,428 KB
testcase_16 AC 336 ms
90,688 KB
testcase_17 AC 356 ms
90,484 KB
testcase_18 AC 303 ms
90,484 KB
testcase_19 AC 301 ms
90,540 KB
testcase_20 AC 311 ms
90,748 KB
testcase_21 AC 349 ms
90,164 KB
testcase_22 AC 342 ms
90,164 KB
testcase_23 AC 341 ms
90,164 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 318 ms
90,748 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 295 ms
90,164 KB
testcase_33 AC 301 ms
90,164 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)]
    
    r_acm = [1]*W
    c_acm = [1]*H
    
    zero = 0
    z_r = [0]*W
    z_c = [0]*H
    sm = 1
    for i in range(H):
        for j in range(W):
            if A[i][j] == 0:
                z_r[j] += 1
                z_c[i] += 1
                zero += 1
            else:
                sm *= A[i][j]
                r_acm[j] *= A[i][j]
                c_acm[i] *= A[i][j]
                
                sm %= mod1
                r_acm[j] %= mod1
                c_acm[i] %= mod1
    
    Q = int(input())
    for _ in range(Q):
        r,c = map(int, input().split())
        
        r -= 1
        c -= 1
        
        z = zero-z_r[c]-z_c[r]+int(A[r][c]==0)
        
        if z > 0:
            print(0)
        else:
            ans = sm * pow(r_acm[c]*c_acm[r]%mod1,mod1-2,mod1) % mod1 * int(A[r][c] != 0)*A[r][c] % mod1
            print(ans)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0