結果

問題 No.1141 田グリッド
ユーザー eQeeQe
提出日時 2020-08-20 23:53:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 159,736 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-21 19:24:31
合計ジャッジ時間 6,998 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,656 KB
testcase_01 AC 4 ms
6,400 KB
testcase_02 AC 5 ms
6,656 KB
testcase_03 AC 4 ms
6,528 KB
testcase_04 AC 4 ms
6,528 KB
testcase_05 AC 4 ms
6,656 KB
testcase_06 AC 5 ms
6,656 KB
testcase_07 AC 4 ms
6,528 KB
testcase_08 AC 7 ms
6,784 KB
testcase_09 AC 6 ms
6,656 KB
testcase_10 AC 8 ms
6,784 KB
testcase_11 AC 8 ms
6,528 KB
testcase_12 AC 7 ms
6,784 KB
testcase_13 AC 167 ms
11,264 KB
testcase_14 AC 166 ms
11,136 KB
testcase_15 AC 153 ms
7,296 KB
testcase_16 AC 155 ms
7,296 KB
testcase_17 AC 151 ms
7,424 KB
testcase_18 AC 136 ms
7,424 KB
testcase_19 AC 142 ms
7,296 KB
testcase_20 AC 140 ms
7,424 KB
testcase_21 AC 150 ms
7,424 KB
testcase_22 AC 159 ms
7,296 KB
testcase_23 AC 154 ms
7,296 KB
testcase_24 AC 140 ms
7,424 KB
testcase_25 AC 140 ms
7,552 KB
testcase_26 AC 140 ms
7,296 KB
testcase_27 AC 140 ms
7,424 KB
testcase_28 AC 145 ms
7,680 KB
testcase_29 AC 140 ms
7,296 KB
testcase_30 AC 143 ms
7,424 KB
testcase_31 AC 136 ms
7,296 KB
testcase_32 AC 140 ms
7,424 KB
testcase_33 AC 140 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];

ll mop(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) (res*=x)%=MOD;
    (x*=x)%=MOD;
    n>>=1;
  }
  return res;
}

int main(void) {
  ll i, j, k;
  
  ll H, W;
  cin >> H >> W;
  ll a[H+10][W+10];
  ll zh[MAX]={}, zw[MAX]={};
  ll mh[MAX], mw[MAX];
  ll M=1;
  ll Z=0;
  
  for(i=0; i<H; i++) mh[i]=1;
  for(i=0; i<W; i++) mw[i]=1;
  
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      cin >> a[i][j];
      if(a[i][j]==0) {
        Z++;
        zh[i]++;
        zw[j]++;
      }else {
        (M*=a[i][j])%=MOD;
        (mh[i]*=a[i][j])%=MOD;
        (mw[j]*=a[i][j])%=MOD;
      }
    }
  }
  
  
  ll Q;
  cin >> Q;
  for(ll _=0; _<Q; _++) {
    ll r, c;
    cin >> r >> c;
    r--; c--;
    
    ll z=zh[r]+zw[c]-(a[r][c]==0);
    if(z==Z) {
      if(a[r][c]==0)
        pt(M*mop(mh[r], MOD-2)%MOD*mop(mw[c], MOD-2)%MOD);
      else
        pt(M*a[r][c]%MOD*mop(mh[r], MOD-2)%MOD*mop(mw[c], MOD-2)%MOD);
    }else {
      pt(0);
    }
    
    
    
  }
  
  
  
  
  
  
}
 
 


0