結果

問題 No.1141 田グリッド
ユーザー anagohirameanagohirame
提出日時 2020-07-31 22:48:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 89,740 KB
最終ジャッジ日時 2023-09-21 01:25:36
合計ジャッジ時間 6,610 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,296 KB
testcase_01 AC 72 ms
71,332 KB
testcase_02 AC 72 ms
71,404 KB
testcase_03 AC 71 ms
71,276 KB
testcase_04 AC 72 ms
71,292 KB
testcase_05 AC 72 ms
71,308 KB
testcase_06 AC 72 ms
71,392 KB
testcase_07 AC 72 ms
71,272 KB
testcase_08 AC 86 ms
76,900 KB
testcase_09 AC 83 ms
76,672 KB
testcase_10 AC 84 ms
76,936 KB
testcase_11 AC 83 ms
76,556 KB
testcase_12 AC 88 ms
76,496 KB
testcase_13 AC 220 ms
89,740 KB
testcase_14 AC 248 ms
84,616 KB
testcase_15 AC 209 ms
78,960 KB
testcase_16 AC 210 ms
78,716 KB
testcase_17 AC 212 ms
78,812 KB
testcase_18 AC 124 ms
78,572 KB
testcase_19 AC 127 ms
78,540 KB
testcase_20 AC 125 ms
78,684 KB
testcase_21 AC 208 ms
78,800 KB
testcase_22 AC 206 ms
78,856 KB
testcase_23 AC 208 ms
78,804 KB
testcase_24 AC 134 ms
78,684 KB
testcase_25 AC 138 ms
79,144 KB
testcase_26 AC 137 ms
78,996 KB
testcase_27 AC 139 ms
79,068 KB
testcase_28 AC 138 ms
79,224 KB
testcase_29 AC 125 ms
78,536 KB
testcase_30 AC 132 ms
78,476 KB
testcase_31 AC 127 ms
78,520 KB
testcase_32 AC 130 ms
78,568 KB
testcase_33 AC 125 ms
78,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

MOD = 10**9+7

H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

r_zero = [0 for _ in range(H)]
c_zero = [0 for _ in range(W)]
tot_zero = 0
r = [1 for _ in range(H)]
c = [1 for _ in range(W)]
tot = 1
for h in range(H):
	for w in range(W):
		if a[h][w] == 0:
			r_zero[h] += 1
			c_zero[w] += 1
			tot_zero += 1
		else:
			r[h] *= a[h][w]
			r[h] %= MOD
			c[w] *= a[h][w]
			c[w] %= MOD
			tot *= a[h][w]
			tot %= MOD

for _ in range(int(input())):
	x, y = map(int, input().split())
	x, y = x-1, y-1
	res = tot
	if r_zero[x] + c_zero[y] - (a[x][y] == 0) != tot_zero:
		print(0)
	else:
		res *= pow(r[x], MOD-2, MOD) * pow(c[y], MOD-2, MOD)
		if a[x][y] != 0:
			res *= a[x][y]
		print(res%MOD)
0