結果

問題 No.1141 田グリッド
ユーザー marroncastlemarroncastle
提出日時 2020-07-31 22:30:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,191 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 92,032 KB
最終ジャッジ日時 2023-09-21 00:54:38
合計ジャッジ時間 7,697 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,620 KB
testcase_01 AC 90 ms
71,688 KB
testcase_02 AC 91 ms
71,412 KB
testcase_03 AC 91 ms
71,424 KB
testcase_04 AC 91 ms
71,580 KB
testcase_05 AC 92 ms
71,676 KB
testcase_06 AC 92 ms
71,576 KB
testcase_07 AC 93 ms
71,564 KB
testcase_08 AC 117 ms
77,724 KB
testcase_09 AC 110 ms
77,760 KB
testcase_10 AC 115 ms
77,712 KB
testcase_11 AC 113 ms
77,404 KB
testcase_12 AC 121 ms
77,480 KB
testcase_13 AC 241 ms
92,032 KB
testcase_14 AC 295 ms
87,664 KB
testcase_15 AC 226 ms
81,584 KB
testcase_16 AC 238 ms
81,644 KB
testcase_17 AC 237 ms
81,632 KB
testcase_18 AC 181 ms
81,960 KB
testcase_19 AC 182 ms
81,404 KB
testcase_20 AC 182 ms
81,248 KB
testcase_21 AC 231 ms
81,792 KB
testcase_22 AC 226 ms
81,516 KB
testcase_23 AC 231 ms
81,592 KB
testcase_24 AC 181 ms
81,352 KB
testcase_25 AC 182 ms
81,020 KB
testcase_26 AC 193 ms
81,336 KB
testcase_27 AC 192 ms
81,164 KB
testcase_28 AC 177 ms
81,088 KB
testcase_29 AC 179 ms
80,984 KB
testcase_30 AC 190 ms
81,132 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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,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')
0