結果

問題 No.1141 田グリッド
ユーザー rnanornano
提出日時 2023-08-21 13:41:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 2,980 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 172,560 KB
実行使用メモリ 7,596 KB
最終ジャッジ日時 2023-08-21 13:41:28
合計ジャッジ時間 5,951 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,104 KB
testcase_01 AC 3 ms
4,880 KB
testcase_02 AC 3 ms
5,156 KB
testcase_03 AC 2 ms
4,880 KB
testcase_04 AC 3 ms
4,856 KB
testcase_05 AC 2 ms
4,948 KB
testcase_06 AC 2 ms
5,104 KB
testcase_07 AC 2 ms
4,880 KB
testcase_08 AC 3 ms
5,180 KB
testcase_09 AC 3 ms
4,944 KB
testcase_10 AC 3 ms
4,956 KB
testcase_11 AC 4 ms
4,988 KB
testcase_12 AC 3 ms
4,952 KB
testcase_13 AC 115 ms
5,832 KB
testcase_14 AC 120 ms
7,596 KB
testcase_15 AC 113 ms
5,404 KB
testcase_16 AC 113 ms
5,400 KB
testcase_17 AC 116 ms
5,396 KB
testcase_18 AC 92 ms
5,364 KB
testcase_19 AC 91 ms
5,400 KB
testcase_20 AC 92 ms
5,376 KB
testcase_21 AC 113 ms
5,316 KB
testcase_22 AC 111 ms
5,312 KB
testcase_23 AC 114 ms
5,300 KB
testcase_24 AC 93 ms
5,376 KB
testcase_25 AC 92 ms
5,404 KB
testcase_26 AC 91 ms
5,356 KB
testcase_27 AC 90 ms
5,300 KB
testcase_28 AC 92 ms
5,384 KB
testcase_29 AC 92 ms
5,568 KB
testcase_30 AC 93 ms
5,476 KB
testcase_31 AC 93 ms
5,416 KB
testcase_32 AC 91 ms
5,364 KB
testcase_33 AC 91 ms
5,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n-1); i >= 0; --i)
#define Rep(i,a,b) for (int i = a; i < b; ++i)
#define rRep(i,a,b) for (int i = a; i > b; --i)
#define fore(i,a) for(auto &i:a)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define Bit(x,i) (((x)>>(i))&1)
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
struct settings{settings(){ios_base::sync_with_stdio(0); cin.tie(0); cout<<fixed<<setprecision(15);};}settingss;
const double PI = acos(-1);
const int INF = 1001001001;
const ll LINF = 1001001001001001001LL;

const int mod = 1000000007;
class modint {
  long long x;
public:
  modint(long long x=0) : x((x%mod+mod)%mod) {}
  modint operator-() const {
    return modint(-x);
  }
  modint& operator+=(const modint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator-=(const modint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator*=(const  modint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint operator+(const modint& a) const {
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint& a) const {
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint& a) const {
    modint res(*this);
    return res*=a;
  }
  modint pow(ll t) const {
    if (!t) return 1;
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  modint inv() const {
    return pow(mod-2);
  }
  modint& operator/=(const modint& a) {
    return (*this) *= a.inv();
  }
  modint operator/(const modint& a) const {
    modint res(*this);
    return res/=a;
  }
  friend ostream& operator<<(ostream& os, const modint& m){
    os << m.x;
    return os;
  }
};

modint pH[100010], pW[100010];
ll zH[100010], zW[100010];

int main() {
  ll H, W; cin >> H >> W;
  vvll A(H, vll(W));
  modint al = 1;
  ll zal = 0;
  rep(i, H) pH[i] = 1;
  rep(j, W) pW[j] = 1;
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
      if(A[i][j]) {
        al *= A[i][j];
        pH[i] *= A[i][j];
        pW[j] *= A[i][j];
      } else {
        zH[i]++;
        zW[j]++;
        zal++;
      }
    }
  }
  int Q; cin >> Q;
  while(Q--) {
    int r, c; cin >> r >> c; --r; --c;
    ll cntz = zal - (zH[r] + zW[c]) + (A[r][c] == 0LL);
    if(cntz) {
      cout << 0 << endl;
      continue;
    }
    modint ans = al;
    ans /= pH[r];
    ans /= pW[c];
    if(A[r][c]) ans *= A[r][c];
    cout << ans << endl;
  }
}
0