結果

問題 No.1141 田グリッド
ユーザー trineutrontrineutron
提出日時 2020-08-02 07:17:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 967 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 11,056 KB
実行使用メモリ 20,604 KB
最終ジャッジ日時 2023-09-25 03:43:11
合計ジャッジ時間 15,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,296 KB
testcase_01 AC 16 ms
8,296 KB
testcase_02 AC 16 ms
8,232 KB
testcase_03 AC 16 ms
8,292 KB
testcase_04 AC 17 ms
8,232 KB
testcase_05 AC 16 ms
7,964 KB
testcase_06 AC 17 ms
8,244 KB
testcase_07 AC 17 ms
8,256 KB
testcase_08 AC 26 ms
8,584 KB
testcase_09 AC 22 ms
8,240 KB
testcase_10 AC 27 ms
8,484 KB
testcase_11 AC 29 ms
8,580 KB
testcase_12 AC 27 ms
8,516 KB
testcase_13 AC 844 ms
16,836 KB
testcase_14 AC 967 ms
20,604 KB
testcase_15 AC 824 ms
12,120 KB
testcase_16 AC 828 ms
12,356 KB
testcase_17 AC 830 ms
12,364 KB
testcase_18 AC 477 ms
12,260 KB
testcase_19 AC 493 ms
12,308 KB
testcase_20 AC 488 ms
12,268 KB
testcase_21 AC 837 ms
12,284 KB
testcase_22 AC 840 ms
12,184 KB
testcase_23 AC 813 ms
12,444 KB
testcase_24 AC 481 ms
12,264 KB
testcase_25 AC 482 ms
12,656 KB
testcase_26 AC 466 ms
12,156 KB
testcase_27 AC 480 ms
12,372 KB
testcase_28 AC 481 ms
12,580 KB
testcase_29 AC 456 ms
12,380 KB
testcase_30 AC 486 ms
12,260 KB
testcase_31 AC 472 ms
12,296 KB
testcase_32 AC 471 ms
12,268 KB
testcase_33 AC 486 ms
12,256 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 a[r - 1][c - 1] and 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)
    elif 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) % mod)
    else:
        print(0)
0