結果

問題 No.1141 田グリッド
ユーザー NNMochiNNMochi
提出日時 2020-07-31 22:41:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 2,430 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 181,888 KB
実行使用メモリ 13,912 KB
最終ジャッジ日時 2023-09-21 01:14:27
合計ジャッジ時間 6,167 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 125 ms
6,608 KB
testcase_14 AC 157 ms
13,912 KB
testcase_15 AC 123 ms
6,124 KB
testcase_16 AC 126 ms
6,256 KB
testcase_17 AC 127 ms
6,252 KB
testcase_18 AC 92 ms
6,256 KB
testcase_19 AC 93 ms
6,108 KB
testcase_20 AC 94 ms
6,180 KB
testcase_21 AC 122 ms
6,172 KB
testcase_22 AC 124 ms
6,252 KB
testcase_23 AC 123 ms
6,160 KB
testcase_24 AC 92 ms
6,156 KB
testcase_25 AC 91 ms
6,160 KB
testcase_26 AC 93 ms
6,260 KB
testcase_27 AC 95 ms
6,124 KB
testcase_28 AC 92 ms
6,256 KB
testcase_29 AC 93 ms
6,160 KB
testcase_30 AC 91 ms
6,248 KB
testcase_31 AC 101 ms
6,164 KB
testcase_32 AC 90 ms
6,168 KB
testcase_33 AC 92 ms
6,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll pow_mod(ll x,ll y){
    if(y==0){
        return 1;
    }
    if(y%2==1){
        return x*pow_mod(x,y-1)%MOD;
    }
    else{
        ll t=pow_mod(x,y/2);
        return t*t%MOD;
    }
}
ll inv(ll x){
    return pow_mod(x,MOD-2);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vvl A(H,vl(W,0));
    vvl B(H,vl(W,0));
    set<P> st;
    multiset<ll> st0,st1;
    rep(i,H){
        rep(j,W){
            cin >> A[i][j];
            B[i][j]=A[i][j];
            if(A[i][j]==0){
                A[i][j]=1;
                st.insert({i,j});
                st0.insert(i);
                st1.insert(j);
            }
        }
    }
    vvl acc0(H,vl(W,0));//yoko;
    vvl acc1(H,vl(W,0));
    ll sum=1;
    rep(i,H){
        rep(j,W){
            if(j==0){
                acc0[i][j]=A[i][j];
            }
            else{
                acc0[i][j]=(acc0[i][j-1]*A[i][j])%MOD;
            }
        }
    }
    rep(j,W){
        rep(i,H){
            if(i==0){
                acc1[i][j]=A[i][j];
            }
            else{
                acc1[i][j]=acc1[i-1][j]*A[i][j]%MOD;
            }
        }
    }
    rep(i,H){
        sum*=acc0[i][W-1];
        sum%=MOD;
    }
    ll Q;
    cin >> Q;
    rep(qq,Q){
        ll r,c;
        cin >> r >> c;
        r--;c--;
        if((B[r][c]!=0&&st.size()==st0.count(r)+st1.count(c))||((B[r][c]==0)&&st.size()+1==st0.count(r)+st1.count(c))){
            cout << (sum*A[r][c])%MOD*(inv(acc0[r][W-1])*inv(acc1[H-1][c])%MOD)%MOD << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
}
0