結果

問題 No.1141 田グリッド
ユーザー trineutrontrineutron
提出日時 2020-08-02 06:51:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 10,760 KB
実行使用メモリ 20,508 KB
最終ジャッジ日時 2023-09-25 02:39:29
合計ジャッジ時間 15,386 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,888 KB
testcase_01 AC 17 ms
7,800 KB
testcase_02 AC 16 ms
7,892 KB
testcase_03 AC 16 ms
7,940 KB
testcase_04 AC 16 ms
7,932 KB
testcase_05 AC 16 ms
7,728 KB
testcase_06 AC 16 ms
7,832 KB
testcase_07 AC 16 ms
7,808 KB
testcase_08 AC 25 ms
8,408 KB
testcase_09 AC 22 ms
8,432 KB
testcase_10 AC 26 ms
8,472 KB
testcase_11 AC 28 ms
8,500 KB
testcase_12 AC 26 ms
8,684 KB
testcase_13 AC 838 ms
16,608 KB
testcase_14 AC 964 ms
20,508 KB
testcase_15 AC 826 ms
12,064 KB
testcase_16 AC 811 ms
12,020 KB
testcase_17 AC 827 ms
12,252 KB
testcase_18 AC 448 ms
12,340 KB
testcase_19 AC 450 ms
12,176 KB
testcase_20 AC 441 ms
11,996 KB
testcase_21 AC 817 ms
12,284 KB
testcase_22 AC 818 ms
12,116 KB
testcase_23 AC 814 ms
12,280 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 448 ms
12,068 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 443 ms
12,140 KB
testcase_33 AC 445 ms
12,180 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
    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