結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-31 22:27:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,174 bytes |
| コンパイル時間 | 421 ms |
| コンパイル使用メモリ | 82,324 KB |
| 実行使用メモリ | 89,728 KB |
| 最終ジャッジ日時 | 2024-07-06 18:53:36 |
| 合計ジャッジ時間 | 5,110 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 3 |
ソースコード
from collections import defaultdict
from collections import Counter
def solve():
mod = 10**9+7
H, W = map(int, input().split())
h_prod = [1]*H
w_prod = [1]*W
A = [list(map(int, input().split())) for _ in range(H)]
h_zero,w_zero = [],[]
for i in range(H):
for j in range(W):
if A[i][j]==0:
h_zero.append(i)
w_zero.append(j)
continue
h_prod[i] *= A[i][j]
w_prod[j] *= A[i][j]
h_prod[i] %= mod
w_prod[j] %= mod
h_zero,w_zero = list(set(h_zero)),list(set(w_zero))
hl,wl = len(h_zero),len(w_zero)
Q = int(input())
if hl>1 and wl>1:
return [0]*Q
total = 1
for i in range(H):
total *= h_prod[i]
total %= mod
ans = [total]*Q
for i in range(Q):
r,c = map(int, input().split())
if hl==1 and wl>1 and r-1!=h_zero[0]:
ans[i] = 0
continue
if hl>1 and wl==1 and c-1!=w_zero[0]:
ans[i] = 0
continue
if hl==1 and wl==1 and r-1!=h_zero[0] and c-1!=w_zero[0]:
ans[i] = 0
continue
ans[i] *= pow(h_prod[r-1]*w_prod[c-1],mod-2,mod)
if A[r-1][c-1]!=0:
ans[i] *= A[r-1][c-1]
ans[i] %= mod
return ans
print(*solve(),sep='\n')