結果

問題 No.1141 田グリッド
ユーザー tyawanmusityawanmusi
提出日時 2020-07-31 21:51:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 972 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 20,392 KB
最終ジャッジ日時 2023-09-20 22:56:36
合計ジャッジ時間 14,870 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,916 KB
testcase_01 AC 16 ms
7,828 KB
testcase_02 AC 18 ms
7,912 KB
testcase_03 AC 17 ms
7,920 KB
testcase_04 AC 16 ms
7,900 KB
testcase_05 AC 16 ms
7,780 KB
testcase_06 AC 16 ms
7,812 KB
testcase_07 AC 16 ms
7,832 KB
testcase_08 AC 25 ms
8,440 KB
testcase_09 AC 21 ms
8,448 KB
testcase_10 AC 26 ms
8,636 KB
testcase_11 AC 28 ms
8,544 KB
testcase_12 AC 26 ms
8,476 KB
testcase_13 AC 840 ms
16,924 KB
testcase_14 AC 972 ms
20,392 KB
testcase_15 AC 818 ms
12,208 KB
testcase_16 AC 818 ms
12,164 KB
testcase_17 AC 814 ms
12,180 KB
testcase_18 AC 447 ms
12,220 KB
testcase_19 AC 441 ms
12,172 KB
testcase_20 AC 451 ms
12,004 KB
testcase_21 AC 828 ms
12,200 KB
testcase_22 AC 823 ms
12,084 KB
testcase_23 AC 818 ms
12,336 KB
testcase_24 AC 448 ms
12,136 KB
testcase_25 AC 466 ms
12,292 KB
testcase_26 AC 456 ms
12,320 KB
testcase_27 AC 440 ms
12,160 KB
testcase_28 AC 458 ms
12,528 KB
testcase_29 AC 450 ms
12,196 KB
testcase_30 AC 446 ms
12,068 KB
testcase_31 AC 445 ms
12,332 KB
testcase_32 AC 441 ms
12,084 KB
testcase_33 AC 434 ms
12,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
h,w=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(h)]
rr=[1]*h
cc=[1]*w
zrr=[0]*h
zcc=[0]*w
z=0
ans=1
for i in range(h):
  for j in range(w):
    if a[i][j]==0:
      zrr[i]+=1
      zcc[j]+=1
      z+=1
      continue
    ans*=a[i][j]
    ans%=mod
    rr[i]*=a[i][j]
    rr[i]%=mod
    cc[j]*=a[i][j]
    cc[j]%=mod
for _ in range(int(input())):
  r,c=map(int,input().split())
  if z-zrr[r-1]-zcc[c-1]+(a[r-1][c-1]==0):print(0)
  else:print((ans*pow(rr[r-1],mod-2,mod)*pow(cc[c-1],mod-2,mod)*(a[r-1][c-1] if a[r-1][c-1] else 1))%mod)
0