結果

問題 No.1141 田グリッド
ユーザー convexineqconvexineq
提出日時 2021-05-10 07:01:22
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 800 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 88,224 KB
最終ジャッジ日時 2023-10-19 15:20:37
合計ジャッジ時間 9,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,296 KB
testcase_01 AC 36 ms
53,296 KB
testcase_02 AC 37 ms
53,296 KB
testcase_03 AC 37 ms
53,296 KB
testcase_04 AC 36 ms
53,296 KB
testcase_05 AC 36 ms
53,296 KB
testcase_06 AC 36 ms
53,296 KB
testcase_07 AC 37 ms
53,296 KB
testcase_08 AC 58 ms
66,304 KB
testcase_09 AC 53 ms
64,176 KB
testcase_10 AC 58 ms
66,304 KB
testcase_11 AC 51 ms
64,176 KB
testcase_12 AC 63 ms
68,372 KB
testcase_13 AC 265 ms
88,224 KB
testcase_14 AC 345 ms
82,396 KB
testcase_15 AC 272 ms
77,696 KB
testcase_16 AC 263 ms
77,992 KB
testcase_17 AC 276 ms
77,948 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 258 ms
77,896 KB
testcase_22 AC 255 ms
77,900 KB
testcase_23 AC 257 ms
77,896 KB
testcase_24 RE -
testcase_25 WA -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 WA -
testcase_32 AC 203 ms
77,720 KB
testcase_33 AC 203 ms
77,716 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[i] += 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*a[r][c]%MOD)
0