結果

問題 No.1141 田グリッド
ユーザー erbowlerbowl
提出日時 2021-01-30 12:57:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,793 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 204,732 KB
実行使用メモリ 6,924 KB
最終ジャッジ日時 2023-09-10 09:40:19
合計ジャッジ時間 7,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 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 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 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,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 148 ms
4,996 KB
testcase_14 AC 155 ms
6,924 KB
testcase_15 AC 144 ms
4,380 KB
testcase_16 AC 143 ms
4,376 KB
testcase_17 AC 140 ms
4,380 KB
testcase_18 AC 127 ms
4,376 KB
testcase_19 AC 129 ms
4,380 KB
testcase_20 AC 128 ms
4,380 KB
testcase_21 AC 142 ms
4,376 KB
testcase_22 AC 142 ms
4,388 KB
testcase_23 AC 144 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 129 ms
4,408 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 129 ms
4,380 KB
testcase_33 AC 128 ms
4,388 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] %MOD << std::endl;
        }
    }
}
0