結果

問題 No.1141 田グリッド
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-23 22:18:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,350 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 102,484 KB
最終ジャッジ日時 2023-10-21 15:20:06
合計ジャッジ時間 5,172 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,628 KB
testcase_01 AC 42 ms
55,628 KB
testcase_02 AC 36 ms
55,628 KB
testcase_03 AC 36 ms
55,628 KB
testcase_04 AC 33 ms
55,628 KB
testcase_05 AC 33 ms
55,628 KB
testcase_06 AC 33 ms
55,628 KB
testcase_07 AC 33 ms
55,628 KB
testcase_08 AC 46 ms
66,560 KB
testcase_09 AC 44 ms
66,556 KB
testcase_10 AC 46 ms
66,560 KB
testcase_11 AC 44 ms
66,692 KB
testcase_12 AC 49 ms
68,644 KB
testcase_13 AC 140 ms
98,100 KB
testcase_14 AC 172 ms
102,484 KB
testcase_15 AC 106 ms
93,776 KB
testcase_16 AC 112 ms
93,776 KB
testcase_17 AC 109 ms
93,776 KB
testcase_18 AC 77 ms
77,268 KB
testcase_19 AC 78 ms
77,184 KB
testcase_20 AC 75 ms
77,208 KB
testcase_21 AC 105 ms
93,776 KB
testcase_22 AC 105 ms
93,776 KB
testcase_23 AC 106 ms
93,776 KB
testcase_24 AC 87 ms
77,384 KB
testcase_25 AC 91 ms
78,500 KB
testcase_26 AC 85 ms
77,476 KB
testcase_27 AC 87 ms
77,404 KB
testcase_28 AC 89 ms
78,136 KB
testcase_29 AC 78 ms
77,320 KB
testcase_30 AC 82 ms
77,420 KB
testcase_31 AC 87 ms
77,460 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

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


zero = 0
cnt_row = [0] * H
cnt_col = [0] * W
ALL = 1
row = [1] * H
col = [1] * W
for i, ai in enumerate(A):
    for j, a in enumerate(ai):
        if a == 0:
            zero += 1
            cnt_row[i] += 1
            cnt_col[j] += 1
        else:
            ALL = ALL * a % mod
            row[i] = row[i] * a % mod
            col[j] = col[j] * a % mod
for i in range(H):
    row[i] = pow(row[i], mod-2, mod)
for j in range(W):
    col[j] = pow(col[j], mod-2, mod)

safe = set()
dr = defaultdict(list)
dc = defaultdict(list)
for i, c in enumerate(cnt_row):
    dr[c].append(i)
for i, c in enumerate(cnt_col):
    dc[c].append(i)
for k, v in dr.items():
    for c in dc[zero - k]:
        for r in v:
            safe.add((r, c))
    for c in dc[zero - k + 1]:
        for r in v:
            if A[r][c] == 0:
                safe.add((r, c))

Q = int(input())
for _ in range(Q):
    r, c = map(int, input().split())
    r -= 1
    c -= 1
    if zero == 0 or (r, c) in safe:
        res = ALL * row[r] * col[c] % mod
        if A[r][c] != 0:
            res *= A[r][c]
        print(res % mod)
    else:
        print(0)
0