結果

問題 No.1141 田グリッド
ユーザー erbowlerbowl
提出日時 2021-01-30 12:51:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,612 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 204,500 KB
実行使用メモリ 6,780 KB
最終ジャッジ日時 2023-09-10 09:33:55
合計ジャッジ時間 8,410 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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]++;
            }
        }
    }
    
    for (int i = 0; i < h; i++) {
        if(rows[i]!=0){
            sum *= rows[i];
            sum %= MOD;
        }
    }
    
    vector<ll> ex(w,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;
        }
    }

    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(rows[r], MOD-2, MOD) %MOD * mod_pow(ex[c], MOD-2, MOD) %MOD * a[r][c] %MOD << std::endl;
        }
    }
}
0