結果
| 問題 | No.1141 田グリッド |
| コンテスト | |
| ユーザー |
c-yan
|
| 提出日時 | 2020-08-01 21:55:35 |
| 言語 | Python3 (3.14.3 + numpy 2.4.2 + scipy 1.17.0) |
| 結果 |
AC
|
| 実行時間 | 526 ms / 2,000 ms |
| コード長 | 905 bytes |
| 記録 | |
| コンパイル時間 | 325 ms |
| コンパイル使用メモリ | 20,832 KB |
| 実行使用メモリ | 29,148 KB |
| 最終ジャッジ日時 | 2026-03-30 01:51:22 |
| 合計ジャッジ時間 | 10,976 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
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')
c-yan