結果

問題 No.1141 田グリッド
ユーザー ryochansq
提出日時 2020-07-31 22:04:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 2,269 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 202,524 KB
最終ジャッジ日時 2025-01-12 10:09:49
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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';
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0