結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2020-12-23 21:58:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,137 bytes |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 82,440 KB |
| 実行使用メモリ | 87,552 KB |
| 最終ジャッジ日時 | 2024-09-21 16:33:35 |
| 合計ジャッジ時間 | 5,012 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 3 |
ソースコード
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))
ALL = 1
row = [1] * H
col = [1] * W
zero = set()
for i, ai in enumerate(A):
for j, a in enumerate(ai):
if a == 0:
zero.add((i, j))
A[i][j] = 1
else:
ALL *= a
row[i] *= a
col[j] *= a
ALL %= mod
row[i] %= mod
col[j] %= 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 = True
R = -1
C = -1
if zero:
safe = False
r_safe = [0] * H
c_safe = [0] * W
for r, c in zero:
r_safe[r] = 1
c_safe[c] = 1
if sum(r_safe) <= 1:
R = r_safe.index(1)
if sum(c_safe) <= 1:
C = c_safe.index(1)
Q = int(input())
for _ in range(Q):
r, c = map(int, input().split())
r -= 1
c -= 1
if safe or r == R or c == C:
res = ALL * row[r] * col[c] * A[r][c] % mod
print(res)
else:
print(0)
tktk_snsn