結果

問題 No.1141 田グリッド
ユーザー ttkkggwwttkkggww
提出日時 2020-07-31 22:56:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,191 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 170,648 KB
実行使用メモリ 6,576 KB
最終ジャッジ日時 2023-09-21 01:45:48
合計ジャッジ時間 6,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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));
	ll cnt0all = 0;
	ll all = 1;
	for(int i = 0;i<h;i++)
	{
		for(int j =0;j<w;j++)
		{
			cin >> A[i][j];
			if(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;
	}
	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;
		if(A[r][c])a = a*A[r][c]%MOD;
		a = a*all%MOD;
		cout << a << endl;
	}
}
0