結果

問題 No.1141 田グリッド
ユーザー c-yanc-yan
提出日時 2020-08-01 21:57:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 497 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 23,488 KB
最終ジャッジ日時 2023-09-22 17:20:34
合計ジャッジ時間 8,808 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,808 KB
testcase_01 AC 18 ms
7,952 KB
testcase_02 AC 15 ms
7,832 KB
testcase_03 AC 16 ms
7,928 KB
testcase_04 AC 17 ms
7,812 KB
testcase_05 AC 17 ms
7,732 KB
testcase_06 AC 16 ms
7,892 KB
testcase_07 AC 15 ms
7,812 KB
testcase_08 AC 23 ms
8,648 KB
testcase_09 AC 20 ms
8,320 KB
testcase_10 AC 23 ms
8,664 KB
testcase_11 AC 27 ms
8,576 KB
testcase_12 AC 24 ms
8,648 KB
testcase_13 AC 453 ms
18,352 KB
testcase_14 AC 497 ms
23,488 KB
testcase_15 AC 429 ms
15,676 KB
testcase_16 AC 430 ms
15,464 KB
testcase_17 AC 434 ms
15,588 KB
testcase_18 AC 240 ms
14,312 KB
testcase_19 AC 231 ms
14,080 KB
testcase_20 AC 237 ms
14,076 KB
testcase_21 AC 429 ms
15,396 KB
testcase_22 AC 443 ms
15,468 KB
testcase_23 AC 440 ms
15,468 KB
testcase_24 AC 244 ms
13,908 KB
testcase_25 AC 246 ms
14,188 KB
testcase_26 AC 241 ms
14,176 KB
testcase_27 AC 239 ms
14,136 KB
testcase_28 AC 240 ms
14,128 KB
testcase_29 AC 236 ms
14,112 KB
testcase_30 AC 241 ms
14,292 KB
testcase_31 AC 239 ms
14,384 KB
testcase_32 AC 238 ms
14,280 KB
testcase_33 AC 230 ms
14,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

readline = open(0).readline

H, W = map(int, readline().split())
A = [list(map(int, readline().split())) for _ in range(H)]
Q = int(readline())

m = 1000000007

total = 1
rows = [1] * H
cols = [1] * W
total0 = 0
rows0 = [0] * H
cols0 = [0] * W
for i in range(H):
    for j in range(W):
        x = A[i][j]
        if x == 0:
            total0 += 1
            rows0[i] += 1
            cols0[j] += 1
        else:
            total *= x
            total %= m
            rows[i] *= x
            rows[i] %= m
            cols[j] *= x
            cols[j] %= m

result = []
for _ in range(Q):
    r, c = map(lambda x: int(x) - 1, readline().split())
    x = A[r][c]
    t = total0 - rows0[r] - cols0[c]
    if x == 0:
        t += 1
    if t > 0:
        result.append(0)
        continue
    t = total * pow(rows[r], -1, m) % m * pow(cols[c], -1, m) % m
    if x != 0:
        t *= x
        t %= m
    result.append(t)
print(*result, sep='\n')
0