結果

問題 No.1141 田グリッド
ユーザー yuji9511yuji9511
提出日時 2020-07-31 23:20:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,237 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 205,576 KB
実行使用メモリ 11,268 KB
最終ジャッジ日時 2023-09-21 02:50:17
合計ジャッジ時間 4,880 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,124 KB
testcase_01 AC 3 ms
4,984 KB
testcase_02 AC 2 ms
5,780 KB
testcase_03 AC 3 ms
5,020 KB
testcase_04 AC 3 ms
5,004 KB
testcase_05 AC 2 ms
5,664 KB
testcase_06 AC 3 ms
5,112 KB
testcase_07 AC 2 ms
5,084 KB
testcase_08 AC 4 ms
5,412 KB
testcase_09 AC 4 ms
5,004 KB
testcase_10 AC 3 ms
5,240 KB
testcase_11 AC 4 ms
5,316 KB
testcase_12 AC 4 ms
5,160 KB
testcase_13 AC 51 ms
8,112 KB
testcase_14 AC 58 ms
11,268 KB
testcase_15 AC 48 ms
6,252 KB
testcase_16 AC 48 ms
6,148 KB
testcase_17 AC 47 ms
6,148 KB
testcase_18 AC 27 ms
7,136 KB
testcase_19 AC 27 ms
6,152 KB
testcase_20 AC 27 ms
6,296 KB
testcase_21 AC 48 ms
6,256 KB
testcase_22 AC 48 ms
7,020 KB
testcase_23 AC 47 ms
7,600 KB
testcase_24 AC 27 ms
6,596 KB
testcase_25 AC 28 ms
6,444 KB
testcase_26 AC 27 ms
6,388 KB
testcase_27 AC 27 ms
6,260 KB
testcase_28 AC 27 ms
7,328 KB
testcase_29 AC 27 ms
6,140 KB
testcase_30 AC 26 ms
7,492 KB
testcase_31 AC 26 ms
6,384 KB
testcase_32 AC 27 ms
6,180 KB
testcase_33 AC 27 ms
6,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
    ll power(ll x, ll n){
        if(n == 0) return 1LL;
        ll res = power(x * x % MOD, n/2);
        if(n % 2 == 1) res = res * x % MOD;
        return res;
    }

void solve(){
    ll H,W;
    cin >> H >> W;
    vector< vector<ll> > A(H+1, vector<ll>(W+1));
    rep(i,0,H){
        rep(j,0,W){
            cin >> A[i][j];
        }
    }
    ll mul = 1;
    rep(i,0,H){
        rep(j,0,W){
            if(A[i][j] != 0){
                mul *= A[i][j];
                mul %= MOD;
            }
        }
    }
    ll tate[100010], yoko[100010];
    rep(i,0,H){
        ll res = 1;
        rep(j,0,W){
            if(A[i][j] != 0){
                res *= A[i][j];
                res %= MOD;
            }
        }
        tate[i] = res;
    }
    rep(j,0,W){
        ll res = 1;
        rep(i,0,H){
            if(A[i][j] != 0){
                res *= A[i][j];
                res %= MOD;
            }
        }
        yoko[j] = res;
    }
    vector< vector<ll> > sum(H+2, vector<ll>(W+2, 0));
    ll n1[100010] = {}, n2[100010] = {};
    ll zero_cnt = 0;
    rep(i,0,H){
        rep(j,0,W){
            if(A[i][j] == 0){
                n1[i]++;
                n2[j]++;
                zero_cnt++;
            }
        }
    }

    ll Q;
    cin >> Q;
    while(Q--){
        ll r,c;
        cin >> r >> c;
        r--; c--;
        ll num = n1[r] + n2[c];
        if(A[r][c] == 0) num--;
        if(num != zero_cnt){
            print(0);
        }else{
            ll ans = mul * power(tate[r], MOD-2) % MOD * power(yoko[c], MOD-2) % MOD;
            if(A[r][c] != 0){
                ans *= A[r][c];
                ans %= MOD;
            }
            print(ans);
        }

    }


}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0