結果
問題 | No.1141 田グリッド |
ユーザー | rokahikou1 |
提出日時 | 2020-08-01 01:05:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,341 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 106,884 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 23:25:54 |
合計ジャッジ時間 | 4,879 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 4 ms
6,940 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 4 ms
6,944 KB |
testcase_11 | AC | 5 ms
6,944 KB |
testcase_12 | AC | 3 ms
6,944 KB |
testcase_13 | AC | 125 ms
6,940 KB |
testcase_14 | AC | 131 ms
6,940 KB |
testcase_15 | AC | 123 ms
6,940 KB |
testcase_16 | AC | 123 ms
6,948 KB |
testcase_17 | AC | 119 ms
6,944 KB |
testcase_18 | AC | 114 ms
6,944 KB |
testcase_19 | AC | 113 ms
6,944 KB |
testcase_20 | AC | 113 ms
6,944 KB |
testcase_21 | AC | 121 ms
6,944 KB |
testcase_22 | AC | 123 ms
6,940 KB |
testcase_23 | AC | 122 ms
6,940 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 <algorithm> #include <cmath> #include <cstdint> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; template <uint_fast64_t MOD> class ModInt { using u64 = uint_fast64_t; public: u64 val; ModInt(const u64 x = 0) : val(x % MOD) {} constexpr u64 &value() { return val; } constexpr ModInt operator-() { return val ? MOD - val : 0; } constexpr ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; } constexpr ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; } constexpr ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; } constexpr ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; } constexpr ModInt &operator+=(const ModInt &rhs) { val += rhs.val; if(val >= MOD) { val -= MOD; } return *this; } constexpr ModInt &operator-=(const ModInt &rhs) { if(val < rhs.val) { val += MOD; } val -= rhs.val; return *this; } constexpr ModInt &operator*=(const ModInt &rhs) { val = val * rhs.val % MOD; return *this; } constexpr ModInt &operator/=(const ModInt &rhs) { *this *= rhs.inv(); return *this; } constexpr bool operator==(const ModInt &rhs) { return this->a == rhs.a; } constexpr bool operator!=(const ModInt &rhs) { return this->a != rhs.a; } friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) { return os << x.val; } friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) { return is >> x.val; } constexpr ModInt inv() const { return ModInt(*this).pow(MOD - 2); } constexpr ModInt pow(ll e) const { u64 x = 1, p = val; while(e > 0) { if(e % 2 == 0) { p = (p * p) % MOD; e /= 2; } else { x = (x * p) % MOD; e--; } } return ModInt(x); } }; using mint = ModInt<MOD>; int main() { int H, W; cin >> H >> W; vector<vector<ll>> A(H, vector<ll>(W)); mint all = 1; set<int> r0, c0; rep(i, H) rep(j, W) { cin >> A[i][j]; if(A[i][j] == 0) { r0.insert(i); c0.insert(j); } else all *= A[i][j]; } vector<mint> row(H), col(W); for(int i = 0; i < H; i++) { mint tmp = 1; for(int j = 0; j < W; j++) { if(A[i][j] != 0) tmp *= A[i][j]; } row[i] = tmp; } for(int i = 0; i < W; i++) { mint tmp = 1; for(int j = 0; j < H; j++) { if(A[j][i] != 0) tmp *= A[j][i]; } col[i] = tmp; } int R = *r0.begin(); int C = *c0.begin(); int Q; cin >> Q; rep(i, Q) { int r, c; cin >> r >> c; r--, c--; if(r0.size() == 0 && c0.size() == 0) { cout << all * A[r][c] / (row[r] * col[c]) << endl; } else if(r0.size() == 1 && c0.size() == 1) { if(R == r || C == r) { cout << all * A[r][c] / (row[r] * col[c]) << endl; } else cout << 0 << endl; } else if(r0.size() == 1 && c0.size() > 1) { if(R == r) { cout << all * A[r][c] / (row[r] * col[c]) << endl; } else { cout << 0 << endl; } } else if(r0.size() > 1 && c0.size() == 1) { if(C == c) { cout << all * A[r][c] / (row[r] * col[c]) << endl; } else { cout << 0 << endl; } } else if(r0.size() > 1 && c0.size() > 1) { cout << 0 << endl; } } return 0; }