結果

問題 No.1141 田グリッド
ユーザー c-yan
提出日時 2020-07-31 23:11:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 760 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 26,240 KB
最終ジャッジ日時 2024-07-06 21:08:22
合計ジャッジ時間 11,741 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

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
totalm = 0
rowsm = [0] * H
colsm = [0] * W
for i in range(H):
for j in range(W):
x = A[i][j]
if x == m or x == 0:
totalm += 1
rowsm[i] += 1
colsm[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 = 0
if x == m or x == 0:
t = 1
if totalm - rowsm[r] - colsm[c] + t > 0:
result.append(0)
else:
if x == m or x == 0:
result.append(total * pow(rows[r], -1, m) % m * pow(cols[c], -1, m) % m)
else:
result.append(total * pow(rows[r], -1, m) % m * pow(cols[c], -1, m) % m * A[r][c] % m)
print(*result, sep='\n')
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0