結果
問題 |
No.1141 田グリッド
|
ユーザー |
|
提出日時 | 2020-07-31 22:30:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,191 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,404 KB |
実行使用メモリ | 89,344 KB |
最終ジャッジ日時 | 2024-07-06 19:38:09 |
合計ジャッジ時間 | 5,045 ms |
ジャッジサーバーID (参考情報) |
judge3 / 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()) 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: ans[i] = 0 continue 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')