結果

問題 No.1141 田グリッド
ユーザー mgingin142857mgingin142857
提出日時 2020-07-31 21:44:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,984 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 170,872 KB
実行使用メモリ 7,344 KB
最終ジャッジ日時 2023-09-20 22:28:13
合計ジャッジ時間 5,768 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 128 ms
5,424 KB
testcase_14 AC 136 ms
7,344 KB
testcase_15 AC 124 ms
4,576 KB
testcase_16 AC 126 ms
4,588 KB
testcase_17 AC 125 ms
4,680 KB
testcase_18 AC 89 ms
4,592 KB
testcase_19 AC 90 ms
4,572 KB
testcase_20 AC 89 ms
4,580 KB
testcase_21 AC 127 ms
4,684 KB
testcase_22 AC 126 ms
4,684 KB
testcase_23 AC 126 ms
4,704 KB
testcase_24 AC 89 ms
4,704 KB
testcase_25 AC 91 ms
4,652 KB
testcase_26 AC 88 ms
4,640 KB
testcase_27 AC 89 ms
4,580 KB
testcase_28 AC 90 ms
4,700 KB
testcase_29 AC 89 ms
4,696 KB
testcase_30 AC 89 ms
4,644 KB
testcase_31 AC 89 ms
4,652 KB
testcase_32 AC 90 ms
4,708 KB
testcase_33 AC 90 ms
4,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0