結果

問題 No.1141 田グリッド
ユーザー chocoruskchocorusk
提出日時 2020-07-31 21:33:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,593 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 129,312 KB
実行使用メモリ 7,992 KB
最終ジャッジ日時 2023-09-20 21:55:47
合計ジャッジ時間 6,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,072 KB
testcase_01 AC 3 ms
6,032 KB
testcase_02 AC 2 ms
6,168 KB
testcase_03 AC 2 ms
6,000 KB
testcase_04 AC 2 ms
6,076 KB
testcase_05 AC 2 ms
6,020 KB
testcase_06 AC 3 ms
6,088 KB
testcase_07 AC 2 ms
6,024 KB
testcase_08 AC 4 ms
6,060 KB
testcase_09 AC 3 ms
6,056 KB
testcase_10 AC 5 ms
6,076 KB
testcase_11 AC 6 ms
6,240 KB
testcase_12 AC 4 ms
6,372 KB
testcase_13 AC 145 ms
6,904 KB
testcase_14 AC 154 ms
7,992 KB
testcase_15 AC 143 ms
6,828 KB
testcase_16 AC 142 ms
6,856 KB
testcase_17 AC 142 ms
6,796 KB
testcase_18 AC 127 ms
6,836 KB
testcase_19 AC 126 ms
6,968 KB
testcase_20 AC 127 ms
6,904 KB
testcase_21 AC 142 ms
6,868 KB
testcase_22 AC 142 ms
6,940 KB
testcase_23 AC 142 ms
7,092 KB
testcase_24 AC 127 ms
7,024 KB
testcase_25 AC 129 ms
6,832 KB
testcase_26 AC 126 ms
7,092 KB
testcase_27 AC 127 ms
6,848 KB
testcase_28 AC 127 ms
6,880 KB
testcase_29 AC 128 ms
6,920 KB
testcase_30 AC 128 ms
6,864 KB
testcase_31 AC 124 ms
6,828 KB
testcase_32 AC 128 ms
6,820 KB
testcase_33 AC 129 ms
6,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
vector<ll> a[100010];
int cnt1[100010], cnt2[100010];
ll p1[100010], p2[100010];
int tot;
ll prod;
int main()
{
	int h, w; cin>>h>>w;
	prod=1;
	for(int i=0; i<h; i++){
		a[i].resize(w);
		for(int j=0; j<w; j++){
			cin>>a[i][j];
			if(a[i][j]!=0) (prod*=a[i][j])%=MOD;
			else tot++;
		}
	}
	for(int i=0; i<h; i++) p1[i]=1;
	for(int j=0; j<w; j++) p2[j]=1;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(a[i][j]==0) cnt1[i]++, cnt2[j]++;
			else (p1[i]*=a[i][j])%=MOD, (p2[j]*=a[i][j])%=MOD;
		}
	}
	int q; cin>>q;
	while(q--){
		int r, c; cin>>r>>c;
		r--; c--;
		int z=tot-cnt1[r]-cnt2[c];
		if(a[r][c]==0) z++;
		if(z==0){
			ll ans=prod*inv(p1[r])%MOD*inv(p2[c])%MOD;
			if(a[r][c]!=0) ans=ans*a[r][c]%MOD;
			cout<<ans<<endl;
		}else{
			cout<<0<<endl;
		}
	}
	return 0;
}
0