結果

問題 No.1141 田グリッド
ユーザー marroncastlemarroncastle
提出日時 2020-07-31 22:52:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 92,508 KB
最終ジャッジ日時 2023-09-21 01:36:52
合計ジャッジ時間 8,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,548 KB
testcase_01 AC 94 ms
71,548 KB
testcase_02 AC 92 ms
71,540 KB
testcase_03 AC 95 ms
71,772 KB
testcase_04 AC 93 ms
71,772 KB
testcase_05 AC 94 ms
71,748 KB
testcase_06 AC 95 ms
71,644 KB
testcase_07 AC 95 ms
71,432 KB
testcase_08 AC 117 ms
77,344 KB
testcase_09 AC 111 ms
77,588 KB
testcase_10 AC 117 ms
77,520 KB
testcase_11 AC 109 ms
77,588 KB
testcase_12 AC 124 ms
77,580 KB
testcase_13 AC 231 ms
92,508 KB
testcase_14 AC 297 ms
88,000 KB
testcase_15 AC 232 ms
81,640 KB
testcase_16 AC 235 ms
81,572 KB
testcase_17 AC 237 ms
81,356 KB
testcase_18 AC 192 ms
81,104 KB
testcase_19 AC 187 ms
81,380 KB
testcase_20 AC 188 ms
81,624 KB
testcase_21 AC 228 ms
81,460 KB
testcase_22 AC 228 ms
81,600 KB
testcase_23 AC 225 ms
81,348 KB
testcase_24 AC 187 ms
81,168 KB
testcase_25 AC 179 ms
81,108 KB
testcase_26 AC 197 ms
81,388 KB
testcase_27 AC 195 ms
81,328 KB
testcase_28 AC 178 ms
80,936 KB
testcase_29 AC 179 ms
81,024 KB
testcase_30 AC 187 ms
80,896 KB
testcase_31 AC 180 ms
81,072 KB
testcase_32 AC 180 ms
81,212 KB
testcase_33 AC 181 ms
81,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = [0]*H
  w_zero = [0]*W
  zero_cnt = 0
  for i in range(H):
    for j in range(W):
      if A[i][j]==0:
        h_zero[i] += 1
        w_zero[j] += 1
        zero_cnt += 1
        continue
      h_prod[i] *= A[i][j]
      w_prod[j] *= A[i][j]
      h_prod[i] %= mod
      w_prod[j] %= mod
  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())
    r -= 1
    c -= 1
    if h_zero[r]+w_zero[c]-(A[r][c]==0)<zero_cnt:
      ans[i] = 0
      continue
    ans[i] *= pow(h_prod[r]*w_prod[c],mod-2,mod)
    if A[r][c]!=0:
      ans[i] *= A[r][c]
    ans[i] %= mod
  return ans
print(*solve(),sep='\n')
0