結果

問題 No.1141 田グリッド
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2020-07-31 23:15:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 3,200 bytes
コンパイル時間 1,140 ms
コンパイル使用メモリ 111,508 KB
実行使用メモリ 6,468 KB
最終ジャッジ日時 2023-09-21 02:41:18
合計ジャッジ時間 3,855 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 48 ms
4,484 KB
testcase_14 AC 56 ms
6,468 KB
testcase_15 AC 47 ms
4,376 KB
testcase_16 AC 47 ms
4,376 KB
testcase_17 AC 47 ms
4,384 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 26 ms
4,380 KB
testcase_20 AC 26 ms
4,380 KB
testcase_21 AC 49 ms
4,380 KB
testcase_22 AC 48 ms
4,376 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 25 ms
4,376 KB
testcase_25 AC 25 ms
4,380 KB
testcase_26 AC 25 ms
4,376 KB
testcase_27 AC 24 ms
4,380 KB
testcase_28 AC 26 ms
4,376 KB
testcase_29 AC 27 ms
4,384 KB
testcase_30 AC 25 ms
4,376 KB
testcase_31 AC 27 ms
4,380 KB
testcase_32 AC 24 ms
4,376 KB
testcase_33 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

// mint N;
//cout << N.x << endl;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W;
  cin >> H >> W;
  vector<vector<mint>> G(H,vector<mint>(W,1));
  vector<int> cnt_H(H,0);
  vector<int> cnt_W(W,0);
  mint all = 1;
  set<P> se;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      int a;
      cin >> a;
      if(a){
        G[i][j] = a;
        all *= a;
      }else{
        se.emplace(i,j);
        cnt_H[i]++;
        cnt_W[j]++;
      }
    }
  }
  vector<mint> sum_H(H,1);
  vector<mint> sum_W(W,1);
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      sum_H[i] *= G[i][j];
      sum_W[j] *= G[i][j];
    }
  }
  int Q;
  cin >> Q;
  for(int i=0; i<Q; i++){
    int r,c;
    cin >> r >> c;
    r--;c--;
    int sum = se.size();
    if(se.count(P(r,c))) sum++;
    if(cnt_H[r] + cnt_W[c] != sum){
      cout << 0 << "\n";
      continue;
    }
    cout << (all/sum_H[r]/sum_W[c]*G[r][c]).x << "\n";
  }
  return 0;
}
0