結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
mgingin142857
|
| 提出日時 | 2020-07-31 21:44:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 2,000 ms |
| コード長 | 1,984 bytes |
| コンパイル時間 | 1,613 ms |
| コンパイル使用メモリ | 174,128 KB |
| 実行使用メモリ | 7,552 KB |
| 最終ジャッジ日時 | 2024-07-06 17:14:54 |
| 合計ジャッジ時間 | 5,109 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll modinv(ll a) {
ll m = mod;
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int i, j;
int h, w;
cin >> h >> w;
ll a[h][w];
VI zi(h, 0), zj(w, 0);
VVI z(h, VI(w, 0));
ll zall = 0;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
cin >> a[i][j];
if (a[i][j] == 0) {
a[i][j] = 1;
zi[i] += 1;
zj[j] += 1;
z[i][j] = 1;
zall++;
}
}
}
VI R(h, 1);
VI C(w, 1);
ll all = 1;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
R[i] *= a[i][j];
R[i] %= mod;
C[j] *= a[i][j];
C[j] %= mod;
all *= a[i][j];
all %= mod;
}
}
int q;
cin >> q;
while (q--) {
int r, c;
cin >> r >> c;
r--;
c--;
ll cntz = zall + z[r][c] - zi[r] - zj[c];
if (cntz > 0){
cout << 0 << endl;
continue;
}
ll ans = all * a[r][c] % mod * modinv(R[r]) % mod * modinv(C[c]) % mod;
cout << ans << endl;
}
}
mgingin142857