結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
Example0911
|
| 提出日時 | 2020-07-31 22:50:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,236 bytes |
| コンパイル時間 | 1,603 ms |
| コンパイル使用メモリ | 177,560 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 20:15:09 |
| 合計ジャッジ時間 | 4,911 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 6 RE * 1 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); i++)
const int inf = 1e9 + 11;
int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
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 {
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;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w; cin >> h >> w;
mint ans = 1;
vector<vector<ll>>a(h, vector<ll>(w));
bool ok = false;
int cnt = 0;
rep(i, h)rep(j, w)cin >> a[i][j];
rep(i, h)rep(j, w) {
if (a[i][j] == 0) {
ok = true; cnt++; continue;
}
ans *= a[i][j];
}
vector<mint>r(h, 1), c(w, 1);
vector<int>isr(h), isc(h);
rep(i, h) {
rep(j, w) {
if (a[i][j] == 0) {
isr[i]++; continue;
}
r[i] *= a[i][j];
}
}
rep(j, w) {
rep(i, h) {
if (a[i][j] == 0) {
isc[j]++; continue;
}
c[j] *= a[i][j];
}
}
int q; cin >> q;
rep(_, q) {
ll x, y; cin >> x >> y; x--; y--;
if (!ok) {
mint now = ans;
mint tmp = r[x]; tmp *= c[y];
tmp /= a[x][y];
now /= tmp;
cout << now.x << endl;
}
else {
if (isr[x] || isc[y]) {
if (isr[x] + isc[y] == cnt) {
mint now = ans;
mint tmp = r[x]; tmp *= c[y];
tmp /= a[x][y];
now /= tmp;
cout << now.x << endl;
}
else cout << 0 << endl;
}
else {
cout << 0 << endl;
}
}
}
return 0;
}
Example0911