結果

問題 No.1141 田グリッド
ユーザー c-yanc-yan
提出日時 2020-08-01 21:55:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 663 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 23,536 KB
最終ジャッジ日時 2023-09-22 17:16:41
合計ジャッジ時間 12,025 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,868 KB
testcase_01 AC 17 ms
7,824 KB
testcase_02 AC 15 ms
7,864 KB
testcase_03 AC 16 ms
7,768 KB
testcase_04 AC 16 ms
7,928 KB
testcase_05 AC 15 ms
7,812 KB
testcase_06 AC 16 ms
7,764 KB
testcase_07 AC 16 ms
7,764 KB
testcase_08 AC 24 ms
8,464 KB
testcase_09 AC 21 ms
8,464 KB
testcase_10 AC 25 ms
8,656 KB
testcase_11 AC 28 ms
8,560 KB
testcase_12 AC 26 ms
8,556 KB
testcase_13 AC 529 ms
18,348 KB
testcase_14 AC 663 ms
23,536 KB
testcase_15 AC 518 ms
15,708 KB
testcase_16 AC 521 ms
15,580 KB
testcase_17 AC 523 ms
15,388 KB
testcase_18 AC 321 ms
14,268 KB
testcase_19 AC 312 ms
14,064 KB
testcase_20 AC 315 ms
14,160 KB
testcase_21 AC 524 ms
15,616 KB
testcase_22 AC 512 ms
15,592 KB
testcase_23 AC 520 ms
15,556 KB
testcase_24 AC 324 ms
14,096 KB
testcase_25 AC 320 ms
14,212 KB
testcase_26 AC 326 ms
14,392 KB
testcase_27 AC 319 ms
13,996 KB
testcase_28 AC 335 ms
14,336 KB
testcase_29 AC 322 ms
14,180 KB
testcase_30 AC 324 ms
14,384 KB
testcase_31 AC 317 ms
14,156 KB
testcase_32 AC 314 ms
14,124 KB
testcase_33 AC 320 ms
14,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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, input().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