結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
c-yan
|
| 提出日時 | 2020-08-01 21:57:07 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 540 ms / 2,000 ms |
| コード長 | 946 bytes |
| コンパイル時間 | 72 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 25,984 KB |
| 最終ジャッジ日時 | 2024-07-08 08:41:13 |
| 合計ジャッジ時間 | 8,938 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
readline = open(0).readline
H, W = map(int, readline().split())
A = [list(map(int, readline().split())) for _ in range(H)]
Q = int(readline())
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, readline().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