結果

問題 No.1141 田グリッド
ユーザー ttkkggwwttkkggww
提出日時 2020-07-31 22:39:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,319 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 173,744 KB
実行使用メモリ 9,384 KB
最終ジャッジ日時 2023-09-21 01:10:52
合計ジャッジ時間 6,976 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 159 ms
5,768 KB
testcase_14 AC 173 ms
9,384 KB
testcase_15 AC 153 ms
4,960 KB
testcase_16 AC 155 ms
4,920 KB
testcase_17 AC 153 ms
4,936 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 158 ms
4,980 KB
testcase_22 AC 154 ms
4,916 KB
testcase_23 AC 156 ms
5,152 KB
testcase_24 WA -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> T mod_pow(T x, T n, const T &p)
{
	T ret = 1;
	while (n > 0)
	{
		if (n & 1) (ret *= x) %= p;
		(x *= x) %= p;
		n >>= 1;
	}
	return ret;
}

const ll MOD = 1e9+7;

int main()
{
	int h,w;
	cin >> h >> w;
	vector<vector<ll>> A(h,vector<ll>(w)),ans(h,vector<ll>(w));
	ll cnt0all = 0;
	ll all = 1;
	for(int i = 0;i<h;i++)
	{
		for(int j =0;j<w;j++)
		{
			cin >> A[i][j];
			all = all*A[i][j]%MOD;
			if(A[i][j]==0)cnt0all++;
		}
	}

	vector<ll> row(h,1),col(w,1),row0(h,0),col0(w,0);
	for(int i = 0;i<h;i++)for(int j = 0;j<w;j++)
	{
		
		if(A[i][j]==0)
		{
			row0[i]++;
			continue;
		}
		row[i] = row[i]*mod_pow(A[i][j],MOD-2,MOD)%MOD;
	}
	for(int i = 0;i<h;i++)for(int j = 0;j<w;j++)
	{
		
		if(A[i][j]==0)
		{
			col0[j]++;
			continue;
		}
		col[j] = col[j]*mod_pow(A[i][j],MOD-2,MOD)%MOD;
	}
	vector<bool> is0r(h),is0l(w);
	for(int i = 0;i<h;i++)
	{
		for(int j = 0;j<w;j++)
			if(A[i][j]==0)is0l[i]=is0r[j] = true;
	}
	int q;
	cin >> q;
	while(q--)
	{
		int now0 = cnt0all;
		ll r,c;
		cin >>r >> c;
		r--;c--;
		now0 -= row0[r] + col0[c] - (A[r][c]==0);
		if(now0>0)
		{
			cout<<0<<endl;
			continue;
		}
		ll a = 1;
		a = a*row[r]%MOD;
		a = a*col[c]%MOD;
		a = a*A[r][c]%MOD;
		a = a*all%MOD;
		cout << a << endl;
	}


}
0