結果

問題 No.1141 田グリッド
ユーザー itohdakitohdak
提出日時 2020-07-31 22:01:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,659 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 210,840 KB
実行使用メモリ 6,256 KB
最終ジャッジ日時 2023-09-20 23:20:52
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 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 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 3 ms
4,376 KB
testcase_13 AC 60 ms
4,380 KB
testcase_14 AC 68 ms
6,256 KB
testcase_15 AC 60 ms
4,376 KB
testcase_16 AC 60 ms
4,376 KB
testcase_17 AC 58 ms
4,376 KB
testcase_18 AC 25 ms
4,376 KB
testcase_19 AC 25 ms
4,376 KB
testcase_20 AC 25 ms
4,376 KB
testcase_21 AC 59 ms
4,376 KB
testcase_22 AC 59 ms
4,376 KB
testcase_23 AC 59 ms
4,376 KB
testcase_24 AC 27 ms
4,440 KB
testcase_25 AC 27 ms
4,380 KB
testcase_26 AC 26 ms
4,380 KB
testcase_27 AC 26 ms
4,384 KB
testcase_28 AC 28 ms
4,376 KB
testcase_29 AC 26 ms
4,376 KB
testcase_30 AC 26 ms
4,384 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

ll modinv(ll a, ll m=mod) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if(u < 0) u += m;
  return u;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  vector<vector<ll>> A(h, vector<ll>(w));
  rep(i, h) rep(j, w) cin >> A[i][j];
  int q; cin >> q;
  vector<ll> mulc(h, 1), mulr(w, 1);
  set<int> zc, zr;
  ll mulAll = 1;
  rep(i, h) rep(j, w) if(A[i][j] == 0) {
    zc.insert(i);
    zr.insert(j);
  }
  rep(i, h) rep(j, w) if(A[i][j] != 0) (mulc[i] *= A[i][j]) %= mod;
  rep(j, w) rep(i, h) if(A[i][j] != 0) (mulr[j] *= A[i][j]) %= mod;
  rep(i, h) rep(j, w) if(A[i][j] != 0) (mulAll *= A[i][j]) %= mod;
  while(q--) {
    int r, c; cin >> r >> c;
    r--; c--;
    if(zc.size() > 1 && zr.size() > 1) {
      cout << 0 << "\n";
    } else if(zc.size() > 1 && !zr.count(c)) {
      cout << 0 << "\n";
    } else if(zr.size() > 1 && !zc.count(r)) {
      cout << 0 << "\n";
    } else if(zc.size() > 0 && zr.size() > 0 &&
              !(zc.count(r) || zr.count(c))) {
      cout << 0 << "\n";
    } else {
      cout << mulAll * modinv(mulc[r]) % mod * modinv(mulr[c]) % mod * (A[r][c] ? A[r][c] : 1) % mod << "\n";
    }
  }
  return 0;
}
0