結果

問題 No.1141 田グリッド
ユーザー ryochansqryochansq
提出日時 2020-07-31 22:04:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 2,269 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 208,992 KB
実行使用メモリ 9,332 KB
最終ジャッジ日時 2023-09-20 23:25:49
合計ジャッジ時間 7,131 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 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,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 156 ms
5,592 KB
testcase_14 AC 172 ms
9,332 KB
testcase_15 AC 151 ms
4,960 KB
testcase_16 AC 152 ms
4,952 KB
testcase_17 AC 151 ms
5,012 KB
testcase_18 AC 129 ms
4,992 KB
testcase_19 AC 125 ms
4,992 KB
testcase_20 AC 128 ms
5,048 KB
testcase_21 AC 154 ms
5,012 KB
testcase_22 AC 151 ms
4,952 KB
testcase_23 AC 152 ms
5,032 KB
testcase_24 AC 127 ms
4,940 KB
testcase_25 AC 127 ms
4,632 KB
testcase_26 AC 127 ms
5,272 KB
testcase_27 AC 129 ms
5,008 KB
testcase_28 AC 128 ms
4,624 KB
testcase_29 AC 127 ms
5,272 KB
testcase_30 AC 130 ms
5,040 KB
testcase_31 AC 127 ms
4,948 KB
testcase_32 AC 129 ms
4,940 KB
testcase_33 AC 128 ms
5,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll h, w;
  cin >> h >> w;
  vector<mint> r(h, 1), c(w, 1);
  vector<vl> a(h, vl(w, 1)), za(h, vl(w, 0));
  vl zr(h, 0), zc(w, 0);
  ll zero = 0;
  mint s = 1;
  rep(i, h) rep(j, w) {
    ll b;
    cin >> b;
    if(b) {
      a[i][j] = b;
      r[i] *= b;
      c[j] *= b;
      s *= b;
    } else {
      za[i][j] = 1;
      zr[i]++;
      zc[j]++;
      zero++;
    }
  }
  ll q;
  cin >> q;
  rep(_, q) {
    ll i, j;
    cin >> i >> j;
    i--;
    j--;
    ll nz = zr[i] + zc[j] - za[i][j];
    if(nz == zero)
      cout << s / r[i] / c[j] * a[i][j] << '\n';
    else
      cout << 0 << '\n';
  }
}
0