結果

問題 No.1141 田グリッド
ユーザー trineutrontrineutron
提出日時 2020-08-02 07:01:22
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,062 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 11,028 KB
実行使用メモリ 20,524 KB
最終ジャッジ日時 2023-09-25 03:05:55
合計ジャッジ時間 15,458 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,252 KB
testcase_01 AC 16 ms
8,224 KB
testcase_02 AC 16 ms
8,284 KB
testcase_03 AC 16 ms
8,236 KB
testcase_04 AC 16 ms
8,252 KB
testcase_05 AC 16 ms
8,128 KB
testcase_06 AC 16 ms
8,200 KB
testcase_07 AC 17 ms
8,196 KB
testcase_08 AC 26 ms
8,260 KB
testcase_09 AC 22 ms
8,364 KB
testcase_10 AC 26 ms
8,592 KB
testcase_11 AC 29 ms
8,508 KB
testcase_12 AC 26 ms
8,632 KB
testcase_13 AC 842 ms
16,872 KB
testcase_14 AC 969 ms
20,524 KB
testcase_15 AC 828 ms
12,152 KB
testcase_16 AC 821 ms
12,008 KB
testcase_17 AC 829 ms
12,248 KB
testcase_18 AC 466 ms
12,212 KB
testcase_19 AC 465 ms
12,172 KB
testcase_20 AC 465 ms
12,120 KB
testcase_21 AC 822 ms
12,332 KB
testcase_22 AC 823 ms
12,320 KB
testcase_23 AC 834 ms
12,248 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 476 ms
12,348 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 456 ms
12,276 KB
testcase_33 AC 465 ms
12,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9 + 7

h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]

product_all = 1
product_row = [1] * h
product_column = [1] * w
zero_all = 0
zero_row = [0] * h
zero_column = [0] * w
for i in range(h):
    for j in range(w):
        if a[i][j]:
            product_all *= a[i][j]
            product_all %= mod
            product_row[i] *= a[i][j]
            product_row[i] %= mod
            product_column[j] *= a[i][j]
            product_column[j] %= mod
        else:
            zero_all += 1
            zero_row[i] += 1
            zero_column[j] += 1

q = int(input())
for i in range(q):
    r, c = map(int, input().split())
    zero_point = 0
    if a[r - 1][c - 1] == 0:
        zero_point += 1
    assert(zero_all - zero_row[r - 1] - zero_column[c - 1] + zero_point >= 0)
    if zero_all - zero_row[r - 1] - zero_column[c - 1] + zero_point == 0:
        print(product_all * pow(product_row[r - 1], mod - 2, mod) * pow(product_column[c - 1], mod - 2, mod) * a[r - 1][c - 1] % mod)
    else:
        print(0)
0