結果
問題 |
No.1141 田グリッド
|
ユーザー |
![]() |
提出日時 | 2020-07-31 22:05:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,722 bytes |
コンパイル時間 | 1,819 ms |
コンパイル使用メモリ | 174,044 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-07-06 18:16:23 |
合計ジャッジ時間 | 5,922 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 10 |
ソースコード
#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<int>>a(h, vector<int>(w)); rep(i, h)rep(j, w)cin >> a[i][j]; rep(i, h)rep(j, w) { ans *= a[i][j]; } vector<mint>r(h, 1), c(w, 1); rep(i, h) { rep(j, w) { r[i] *= a[i][j]; } } rep(j, w) { rep(i, h) { c[j] *= a[i][j]; } } int q; cin >> q; rep(_, q) { int x, y; cin >> x >> y; x--; y--; mint now = ans; mint tmp = r[x]; tmp *= c[y]; tmp /= a[x][y]; now /= tmp; cout << now.x << endl; } return 0; }