結果

問題 No.1141 田グリッド
ユーザー erbowlerbowl
提出日時 2021-01-30 13:05:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,765 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 204,192 KB
実行使用メモリ 7,000 KB
最終ジャッジ日時 2023-09-10 09:47:40
合計ジャッジ時間 7,241 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 147 ms
5,120 KB
testcase_14 AC 154 ms
7,000 KB
testcase_15 AC 143 ms
4,380 KB
testcase_16 AC 146 ms
4,380 KB
testcase_17 AC 140 ms
4,376 KB
testcase_18 AC 127 ms
4,376 KB
testcase_19 AC 129 ms
4,384 KB
testcase_20 AC 129 ms
4,376 KB
testcase_21 AC 142 ms
4,500 KB
testcase_22 AC 142 ms
4,380 KB
testcase_23 AC 142 ms
4,380 KB
testcase_24 AC 127 ms
4,376 KB
testcase_25 AC 129 ms
4,380 KB
testcase_26 AC 129 ms
4,376 KB
testcase_27 AC 129 ms
4,380 KB
testcase_28 AC 129 ms
4,380 KB
testcase_29 AC 129 ms
4,380 KB
testcase_30 AC 126 ms
4,376 KB
testcase_31 AC 127 ms
4,380 KB
testcase_32 AC 127 ms
4,380 KB
testcase_33 AC 132 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

const ll MOD = 1e9+7;
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

int main() {
    ll h,w;
    std::cin >> h>>w;

    vector<vector<ll>> a(h,vector<ll>(w,0));
    vector<ll> rows(h,1), cols(w,1);

    ll zero_count = 0;
    vector<ll> zrows(h,0), zcols(w,0);
    ll sum = 1;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> a[i][j];
            rows[i] *= a[i][j];
            rows[i] %= MOD;
            cols[j] *= a[i][j];
            cols[j] %= MOD;
            if(a[i][j]==0){
                zero_count++;
                zrows[i]++;
                zcols[j]++;
            }
        }
    }

    vector<ll> ex(w,1),ex2(h,1);

    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            if( a[j][i]==0)continue;
            ex[i] *= a[j][i];
            ex[i] %= MOD;
        }
    }
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if( a[i][j]==0)continue;
            ex2[i] *= a[i][j];
            ex2[i] %= MOD;
        }
    }
    
    for (int i = 0; i < h; i++) {
        sum *= ex2[i];
        sum %= MOD;
    }

    ll q;
    std::cin >> q;
    
    for (int i = 0; i < q; i++) {
        ll r,c;
        std::cin >> r>>c;
        r--;c--;

        if(zrows[r]+zcols[c]-(a[r][c]==0) != zero_count ){
            std::cout << 0 << std::endl;
        }else{
            std::cout << sum * mod_pow(ex2[r], MOD-2, MOD) %MOD * mod_pow(ex[c], MOD-2, MOD) %MOD * (a[r][c]==0 ? 1 : a[r][c]) %MOD << std::endl;
        }
    }
}
0