結果

問題 No.1141 田グリッド
ユーザー どららどらら
提出日時 2020-08-01 01:01:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,393 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 175,016 KB
実行使用メモリ 37,428 KB
最終ジャッジ日時 2023-09-21 04:47:43
合計ジャッジ時間 7,829 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
34,248 KB
testcase_01 AC 33 ms
34,132 KB
testcase_02 AC 33 ms
34,072 KB
testcase_03 AC 33 ms
34,244 KB
testcase_04 AC 33 ms
34,316 KB
testcase_05 AC 32 ms
34,004 KB
testcase_06 AC 33 ms
34,084 KB
testcase_07 AC 33 ms
34,088 KB
testcase_08 AC 34 ms
34,280 KB
testcase_09 AC 34 ms
34,200 KB
testcase_10 AC 35 ms
34,252 KB
testcase_11 AC 36 ms
34,316 KB
testcase_12 AC 35 ms
34,172 KB
testcase_13 AC 182 ms
35,116 KB
testcase_14 AC 193 ms
37,428 KB
testcase_15 AC 178 ms
34,488 KB
testcase_16 AC 177 ms
34,520 KB
testcase_17 AC 179 ms
34,624 KB
testcase_18 AC 154 ms
34,628 KB
testcase_19 AC 153 ms
34,576 KB
testcase_20 AC 154 ms
34,572 KB
testcase_21 AC 179 ms
34,696 KB
testcase_22 AC 177 ms
34,664 KB
testcase_23 AC 180 ms
34,584 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:174:18: 警告: ‘xx’ may be used uninitialized [-Wmaybe-uninitialized]
  174 |       if(r == yy && c == xx){
      |          ~~~~~~~~^~~~~~~~~~
main.cpp:151:9: 備考: ‘xx’ はここで定義されています
  151 |     int xx, yy;
      |         ^~
main.cpp:174:7: 警告: ‘yy’ may be used uninitialized [-Wmaybe-uninitialized]
  174 |       if(r == yy && c == xx){
      |       ^~
main.cpp:151:13: 備考: ‘yy’ はここで定義されています
  151 |     int xx, yy;
      |             ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(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 ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 2000005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;



int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> v(H, vector<int>(W));
  mint all(1);
  rep(i,H){
    rep(j,W){
      cin >> v[i][j];
      all *= v[i][j];
    }
  }

  vector<mint> vh(H), vw(W);
  int zh = 0, zw = 0;
  rep(i,H){
    mint tmp(1);
    bool z = false;
    rep(j,W){
      tmp *= v[i][j];
      if(v[i][j] == 0) z = true;
    }
    vh[i] = tmp;
    if(z) zh++;
  }
  rep(i,W){
    mint tmp(1);
    bool z = false;
    rep(j,H){
      tmp *= v[j][i];
      if(v[j][i] == 0) z = true;
    }
    vw[i] = tmp;
    if(z) zw++;
  }

  if(zh >= 2 || zw >= 2){
    int Q;
    cin >> Q;
    rep(i,Q){
      int r, c;
      cin >> r >> c;
      cout << 0 << endl;
    }
  }
  else if(zh == 0){
    int Q;
    cin >> Q;
    rep(i,Q){
      int r, c;
      cin >> r >> c;
      r--;
      c--;
      mint ret = all;
      
      ret *= vh[r].inv();
      ret *= vw[c].inv();
      ret *= v[r][c];
      cout << ret << endl;
    }
  }
  else{
    int xx, yy;
    rep(i,H){
      rep(j,W){
        if(v[i][j] == 0){
          yy = i;
          xx = j;
        }
      }
    }
    all = mint(1);
    rep(i,H){
      rep(j,W){
        if(i == yy || j == xx) continue;
        all *= v[i][j];
      }
    }
    int Q;
    cin >> Q;
    rep(i,Q){
      int r, c;
      cin >> r >> c;
      r--;
      c--;
      if(r == yy && c == xx){
        cout << all << endl;
      }else{
        cout << 0 << endl;
      }
    }
  }
  
  return 0;
}


0