結果

問題 No.1141 田グリッド
コンテスト
ユーザー Rumain831
提出日時 2026-11-02 12:51:06
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,191 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,493 ms
コンパイル使用メモリ 187,108 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-11-02 12:51:18
合計ジャッジ時間 8,242 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

const ll MOD=1e9+7;

struct mint{
  ll val;
  mint(ll val_=0):val(val_%MOD){
    if(val<0) val+=MOD; 
  }

  mint operator-()const{
    return mint(-val);
  }
  mint& operator+=(const mint& other){
    val+=other.val;
    if(val>=MOD) val-=MOD;
    return *this;
  }
  mint& operator-=(const mint& other){
    val-=other.val;
    if(val<0) val+=MOD;
    return *this;
  }
  mint& operator*=(const mint& other){
    val*=other.val, val%=MOD;
    return *this;
  }
  mint pow(ll n) const{
    mint ans(1);
    mint mul(*this);
    while(n){
      if(n&1) ans*=mul;
      mul*=mul;
      n/=2;
    }
    return ans;
  }
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& other){
    return *this*=other.inv();
  }

  friend bool operator==(const mint& lhs, const mint& rhs){
    return lhs.val == rhs.val;
  }
  friend bool operator!=(const mint& lhs, const mint& rhs){
    return lhs.val != rhs.val;
  }
  friend mint operator+(mint lhs, const mint& rhs) {
    lhs+=rhs;
    return lhs;
  }
  friend mint operator-(mint lhs, const mint& rhs) {
    lhs-=rhs;
    return lhs;
  }
  friend mint operator*(mint lhs, const mint& rhs) {
    lhs*=rhs;
    return lhs;
  }
  friend mint operator/(mint lhs, const mint& rhs) {
    lhs/=rhs;
    return lhs;
  }
  friend istream& operator>>(istream& is, mint& m) {
    ll x;
    is >> x;
    m=mint(x);
    return is;
  }
  friend ostream& operator<<(ostream& os, const mint& m) {
    return os << m.val;
  }
};

int main(void){
  int h, w; cin >> h >> w;
  vector a(h, vector<mint>(w));
  vector<mint> tate(h, 1), yoko(w, 1);
  vector<int> t0(h), y0(w);
  mint all=1;
  int a0=0;
  for(int i=0; i<h; i++)for(int j=0; j<w; j++){
    cin >> a[i][j];
    if(a[i][j]==0) t0[i]++, y0[j]++, a0++;
    mint x=(a[i][j]==0?1:a[i][j]);
    tate[i]*=x, yoko[j]*=x;
    all*=x;
  }
  int q; cin >> q;
  while(q--){
    int r, c; cin >> r >> c; r--, c--;
    int zero=a0-(t0[r]+y0[c]-(a[r][c]==0));
    if(zero) cout << 0 << '\n';
    else{
      mint ans=all/(tate[r]*yoko[c])*a[r][c];
      cout << ans << '\n';
    }
  }
  return 0; 
}
0