結果

問題 No.1141 田グリッド
ユーザー Example0911Example0911
提出日時 2020-07-31 22:56:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,190 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 176,116 KB
実行使用メモリ 6,480 KB
最終ジャッジ日時 2023-09-21 01:45:54
合計ジャッジ時間 5,404 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 112 ms
4,380 KB
testcase_14 AC 119 ms
6,480 KB
testcase_15 AC 114 ms
4,380 KB
testcase_16 AC 112 ms
4,380 KB
testcase_17 AC 111 ms
4,380 KB
testcase_18 AC 90 ms
4,380 KB
testcase_19 AC 87 ms
4,380 KB
testcase_20 AC 88 ms
4,380 KB
testcase_21 AC 111 ms
4,380 KB
testcase_22 AC 112 ms
4,376 KB
testcase_23 AC 114 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
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;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); i++)
const int inf = 1e9 + 11;
int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w; cin >> h >> w;
	mint ans = 1;
	vector<vector<ll>>a(h, vector<ll>(w));
	bool ok = false;
	int cnt = 0;
	rep(i, h)rep(j, w)cin >> a[i][j];
	rep(i, h)rep(j, w) {
		if (a[i][j] == 0) {
			ok = true; cnt++; continue;
		}
		ans *= a[i][j];
	}
	vector<mint>r(h, 1), c(w, 1);
	vector<int>isr(h), isc(h);
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == 0) {
				isr[i]++;  continue;
			}
			r[i] *= a[i][j];
		}
	}
	rep(j, w) {
		rep(i, h) {
			if (a[i][j] == 0) {
				isc[j]++; continue;
			}
			c[j] *= a[i][j];
		}
	}
	int q; cin >> q;
	rep(_, q) {
		ll x, y; cin >> x >> y; x--; y--;
		if (!ok) {
			mint now = ans;
			mint tmp = r[x]; tmp *= c[y];
			tmp /= a[x][y];
			now /= tmp;
			cout << now.x << endl;
		}
		else {
			if (isr[x] || isc[y]) {
				if (isr[x] + isc[y] - (int)(a[x][y] == 0)== cnt) {
					mint now = ans;
					
					cout << now.x << endl;
				}
				else cout << 0 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
	}
	return 0;
}
0