結果

問題 No.1141 田グリッド
ユーザー 双六双六
提出日時 2020-07-31 22:07:26
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 91,620 KB
最終ジャッジ日時 2023-09-20 23:33:46
合計ジャッジ時間 7,407 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,672 KB
testcase_01 AC 92 ms
71,620 KB
testcase_02 AC 90 ms
71,528 KB
testcase_03 AC 93 ms
71,448 KB
testcase_04 AC 91 ms
71,508 KB
testcase_05 AC 90 ms
71,436 KB
testcase_06 AC 90 ms
71,532 KB
testcase_07 AC 92 ms
71,728 KB
testcase_08 AC 105 ms
77,700 KB
testcase_09 AC 105 ms
77,512 KB
testcase_10 AC 105 ms
77,364 KB
testcase_11 AC 107 ms
77,572 KB
testcase_12 AC 109 ms
77,500 KB
testcase_13 AC 241 ms
91,620 KB
testcase_14 AC 272 ms
85,348 KB
testcase_15 AC 231 ms
79,488 KB
testcase_16 AC 234 ms
79,524 KB
testcase_17 AC 234 ms
79,300 KB
testcase_18 AC 146 ms
79,228 KB
testcase_19 AC 147 ms
79,136 KB
testcase_20 AC 148 ms
79,132 KB
testcase_21 AC 232 ms
79,688 KB
testcase_22 AC 234 ms
79,592 KB
testcase_23 AC 233 ms
79,392 KB
testcase_24 AC 155 ms
79,412 KB
testcase_25 AC 155 ms
79,480 KB
testcase_26 AC 158 ms
79,396 KB
testcase_27 AC 157 ms
80,360 KB
testcase_28 AC 162 ms
79,328 KB
testcase_29 AC 147 ms
79,200 KB
testcase_30 AC 148 ms
79,384 KB
testcase_31 AC 149 ms
79,292 KB
testcase_32 AC 148 ms
79,348 KB
testcase_33 AC 145 ms
79,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	H, W = getlist()
	table = []
	for i in range(H):
		A = getlist()
		table.append(A)

	Hsum = [1] * H
	Wsum = [1] * W
	Hzero = [0] * H
	Wzero = [0] * W
	zerocnt = 0
	ALL = 1
	for i in range(H):
		for j in range(W):
			if table[i][j] == 0:
				Hzero[i] += 1
				Wzero[j] += 1
				zerocnt += 1
			else:
				ALL = (ALL * table[i][j]) % con
				Wsum[j] = (Wsum[j] * table[i][j]) % con
				Hsum[i] = (Hsum[i] * table[i][j]) % con

	# print(Hsum)
	# print(Wsum)
	# print(ALL)

	# クエリ
	Q = int(input())
	for i in range(Q):
		r, c = getlist()
		r -= 1; c -= 1
		z = Hzero[r] + Wzero[c]
		if table[r][c] == 0:
			z -= 1

		if z == zerocnt:
			ans = ALL * pow(Hsum[r], con - 2, con) * pow(Wsum[c], con - 2, con)
			if table[r][c] != 0:
				ans *= table[r][c]

			ans %= con
			print(ans)
		else:
			print(0)

if __name__ == '__main__':
	main()
0