結果

問題 No.1141 田グリッド
ユーザー marroncastlemarroncastle
提出日時 2020-07-31 22:27:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 91,904 KB
最終ジャッジ日時 2023-09-21 00:07:37
合計ジャッジ時間 7,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,592 KB
testcase_01 AC 96 ms
71,432 KB
testcase_02 AC 96 ms
71,820 KB
testcase_03 AC 96 ms
71,572 KB
testcase_04 AC 96 ms
71,580 KB
testcase_05 AC 94 ms
71,636 KB
testcase_06 AC 96 ms
71,576 KB
testcase_07 AC 97 ms
71,764 KB
testcase_08 AC 121 ms
77,648 KB
testcase_09 AC 113 ms
77,456 KB
testcase_10 AC 120 ms
77,832 KB
testcase_11 AC 116 ms
77,468 KB
testcase_12 AC 127 ms
77,956 KB
testcase_13 AC 246 ms
91,904 KB
testcase_14 AC 313 ms
87,548 KB
testcase_15 AC 238 ms
81,568 KB
testcase_16 AC 246 ms
81,644 KB
testcase_17 AC 245 ms
81,564 KB
testcase_18 AC 146 ms
81,028 KB
testcase_19 AC 142 ms
81,004 KB
testcase_20 AC 142 ms
80,768 KB
testcase_21 AC 235 ms
81,504 KB
testcase_22 AC 233 ms
81,496 KB
testcase_23 AC 232 ms
81,512 KB
testcase_24 AC 185 ms
81,352 KB
testcase_25 AC 185 ms
81,204 KB
testcase_26 AC 197 ms
81,244 KB
testcase_27 AC 193 ms
81,036 KB
testcase_28 AC 178 ms
81,128 KB
testcase_29 AC 179 ms
81,016 KB
testcase_30 AC 186 ms
81,048 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())
  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')
0