結果

問題 No.1141 田グリッド
ユーザー convexineqconvexineq
提出日時 2021-05-10 07:07:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 88,436 KB
最終ジャッジ日時 2023-10-19 15:25:21
合計ジャッジ時間 7,902 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,572 KB
testcase_01 AC 37 ms
53,572 KB
testcase_02 AC 37 ms
53,572 KB
testcase_03 AC 38 ms
53,572 KB
testcase_04 AC 38 ms
53,572 KB
testcase_05 AC 37 ms
53,572 KB
testcase_06 AC 37 ms
53,572 KB
testcase_07 AC 38 ms
53,572 KB
testcase_08 AC 60 ms
66,564 KB
testcase_09 AC 55 ms
64,440 KB
testcase_10 AC 61 ms
66,564 KB
testcase_11 AC 54 ms
64,440 KB
testcase_12 AC 66 ms
68,632 KB
testcase_13 AC 265 ms
88,436 KB
testcase_14 AC 324 ms
82,676 KB
testcase_15 AC 252 ms
77,916 KB
testcase_16 AC 256 ms
78,240 KB
testcase_17 AC 263 ms
78,176 KB
testcase_18 AC 212 ms
77,716 KB
testcase_19 AC 205 ms
77,096 KB
testcase_20 AC 214 ms
77,096 KB
testcase_21 AC 254 ms
78,140 KB
testcase_22 AC 256 ms
78,132 KB
testcase_23 AC 254 ms
78,132 KB
testcase_24 AC 212 ms
77,288 KB
testcase_25 AC 208 ms
77,992 KB
testcase_26 AC 219 ms
77,900 KB
testcase_27 AC 219 ms
78,032 KB
testcase_28 AC 218 ms
78,036 KB
testcase_29 AC 207 ms
77,912 KB
testcase_30 AC 217 ms
77,796 KB
testcase_31 AC 208 ms
77,808 KB
testcase_32 AC 202 ms
77,952 KB
testcase_33 AC 203 ms
77,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9+7
h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]

row = [1]*h
zrow = [0]*h
for i in range(h):
    v = 1
    for j in range(w):
        if a[i][j]:
            v = v*a[i][j]%MOD
        else:
            zrow[i] += 1
    row[i] = v

col = [1]*w
zcol = [0]*w
for j in range(w):
    v = 1
    for i in range(h):
        if a[i][j]:
            v = v*a[i][j]%MOD
        else:
            zcol[j] += 1
    col[j] = v

tot = 1
for v in row: tot = tot*v%MOD
ztot = sum(zrow)

def inv(x):
    assert x
    return pow(x,MOD-2,MOD)

Q = int(input())
for _ in range(Q):
    r,c = map(int,input().split())
    r -= 1
    c -= 1
    if ztot - zrow[r] - zcol[c] + (a[r][c]==0):
        print(0)
    else:
        print(tot*inv(row[r]*col[c]%MOD)%MOD*max(a[r][c],1)%MOD)
0