結果
問題 | No.1141 田グリッド |
ユーザー | QCFium |
提出日時 | 2020-07-31 21:29:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,236 bytes |
コンパイル時間 | 1,508 ms |
コンパイル使用メモリ | 171,452 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 16:27:30 |
合計ジャッジ時間 | 3,944 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 45 ms
5,376 KB |
testcase_14 | AC | 46 ms
5,376 KB |
testcase_15 | AC | 48 ms
5,376 KB |
testcase_16 | AC | 46 ms
5,376 KB |
testcase_17 | AC | 44 ms
5,376 KB |
testcase_18 | AC | 41 ms
5,376 KB |
testcase_19 | AC | 41 ms
5,376 KB |
testcase_20 | AC | 40 ms
5,376 KB |
testcase_21 | AC | 45 ms
5,376 KB |
testcase_22 | AC | 45 ms
5,376 KB |
testcase_23 | AC | 45 ms
5,376 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 | - |
ソースコード
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } #define MOD 1000000007 template<int mod> struct ModInt{ int x; ModInt () : x(0) {} ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {} ModInt &operator += (const ModInt &p){ if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator -= (const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator *= (const ModInt &p) { x = (int64_t) x * p.x % mod; return *this; } ModInt &operator /= (const ModInt &p) { *this *= p.inverse(); return *this; } ModInt &operator ^= (int64_t p) { ModInt res = 1; for (; p; p >>= 1) { if (p & 1) res *= *this; *this *= *this; } return *this = res; } ModInt operator - () const { return ModInt(-x); } ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; } ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; } ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; } bool operator == (const ModInt &p) const { return x == p.x; } bool operator != (const ModInt &p) const { return x != p.x; } explicit operator int() const { return x; } ModInt &operator = (const int p) { x = p; return *this;} ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) { return stream << p.x; } friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) { int64_t x; stream >> x; a = ModInt<mod>(x); return stream; } }; typedef ModInt<1000000007> mint; template<int mod> struct MComb { using mint = ModInt<mod>; std::vector<mint> fact; std::vector<mint> inv; MComb (int n) { // O(n + log(mod)) fact = std::vector<mint>(n + 1, 1); for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i); inv.resize(n + 1); inv[n] = fact[n] ^ (mod - 2); for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1); } mint ncr(int n, int r) { return fact[n] * inv[r] * inv[n - r]; } mint npr(int n, int r) { return fact[n] * inv[n - r]; } mint nhr(int n, int r) { assert(n + r - 1 < (int) fact.size()); return ncr(n + r - 1, r); } }; struct M { int z = 0; mint x = 1; M () = default; M (mint n) : x(n) {} M (int z, mint x) : z(z), x(x) {} M operator * (const M &rhs) { return {z + rhs.z, x * rhs.x}; } M operator / (const M &rhs) { return {z - rhs.z, x / rhs.x}; } mint val() { return z ? 0 : x; } }; int main() { int h = ri(); int w = ri(); M a[h][w]; for (auto &i : a) for (auto &j : i) j = (mint) ri(); M r0[h]; M r1[w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { r0[i] = r0[i] * a[i][j]; r1[j] = r1[j] * a[i][j]; } M all; for (auto &i : a) for (auto j : i) all = all * j; int q = ri(); for (int i = 0; i < q; i++) { int x = ri() - 1; int y = ri() - 1; printf("%d\n", (int) (all / r0[x] / r1[y] * a[x][y]).val()); } return 0; }