結果
問題 | No.1141 田グリッド |
ユーザー | はまやんはまやん |
提出日時 | 2020-08-01 09:41:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 5,579 bytes |
コンパイル時間 | 2,134 ms |
コンパイル使用メモリ | 214,548 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-07-07 17:14:58 |
合計ジャッジ時間 | 5,134 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 54 ms
5,376 KB |
testcase_14 | AC | 69 ms
9,216 KB |
testcase_15 | AC | 57 ms
5,376 KB |
testcase_16 | AC | 53 ms
5,376 KB |
testcase_17 | AC | 54 ms
5,376 KB |
testcase_18 | AC | 23 ms
5,376 KB |
testcase_19 | AC | 23 ms
5,376 KB |
testcase_20 | AC | 21 ms
5,376 KB |
testcase_21 | AC | 60 ms
5,376 KB |
testcase_22 | AC | 57 ms
5,376 KB |
testcase_23 | AC | 53 ms
5,376 KB |
testcase_24 | AC | 22 ms
5,376 KB |
testcase_25 | AC | 23 ms
5,376 KB |
testcase_26 | AC | 24 ms
5,376 KB |
testcase_27 | AC | 23 ms
5,376 KB |
testcase_28 | AC | 23 ms
5,376 KB |
testcase_29 | AC | 23 ms
5,376 KB |
testcase_30 | AC | 21 ms
5,376 KB |
testcase_31 | AC | 21 ms
5,376 KB |
testcase_32 | AC | 22 ms
5,376 KB |
testcase_33 | AC | 22 ms
5,376 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<1000000007> mint; struct Ruisekiwa2D { int VH, VW; using T = int; vector<vector<T>> v; bool needBuild = false; Ruisekiwa2D() { } Ruisekiwa2D(int w, int h) { init(w, h); } void init(int w, int h) { needBuild = true; VH = h; VW = w; v.clear(); v.resize(h, vector<T>(w)); rep(y, 0, VH) rep(x, 0, VW) v[y][x] = 0; } void set(int x, int y, T c) { v[y][x] = c; } void add(int x, int y, T c) { v[y][x] += c; } void build() { rep(y, 0, VH) rep(x, 0, VW) { if (0 < y) v[y][x] += v[y - 1][x]; if (0 < x) v[y][x] += v[y][x - 1]; if (0 < y && 0 < x) v[y][x] -= v[y - 1][x - 1]; } needBuild = false; } // [sx,sy]~[tx,ty] T get(int sx, int tx, int sy, int ty) { if (needBuild) assert(0 && "Need Build"); if (tx < sx or ty < sy) return 0; T rs = v[ty][tx]; if (0 < sx) rs -= v[ty][sx - 1]; if (0 < sy) rs -= v[sy - 1][tx]; if (0 < sx && 0 < sy) rs += v[sy - 1][sx - 1]; return rs; } T getToDown(int x, int y, int len) { if (needBuild) assert(0 && "Need Build"); if (VH - y < len) len = VH - y; return get(x, x, y, y + len - 1); } T getToUp(int x, int y, int len) { if (needBuild) assert(0 && "Need Build"); if (y + 1 < len) len = y + 1; return get(x, x, y - len + 1, y); } }; /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i @hamayanhamayan0 / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int H, W, Q; //--------------------------------------------------------------------------------------------------- void _main() { cin >> H >> W; vector<vector<int>> A(H, vector<int>(W)); rep(y, 0, H) rep(x, 0, W) cin >> A[y][x]; Ruisekiwa2D r2d(W, H); rep(y, 0, H) rep(x, 0, W) if (A[y][x] == 0) { r2d.add(x, y, 1); A[y][x] = 1; } r2d.build(); vector<mint> columns(W, 1); rep(x, 0, W) rep(y, 0, H) columns[x] *= A[y][x]; vector<mint> rows(H, 1); rep(x, 0, W) rep(y, 0, H) rows[y] *= A[y][x]; mint tot = 1; rep(y, 0, H) rep(x, 0, W) tot *= A[y][x]; cin >> Q; rep(_, 0, Q) { int y, x; cin >> y >> x; y--; x--; int zero = 0; zero += r2d.get(0, x - 1, 0, y - 1); // LU zero += r2d.get(0, x - 1, y + 1, H - 1); // LD zero += r2d.get(x + 1, W - 1, 0, y - 1); // RU zero += r2d.get(x + 1, W - 1, y + 1, H - 1); // RD if (0 < zero) printf("0\n"); else { mint ans = tot / columns[x] / rows[y] * A[y][x]; printf("%d\n", ans.get()); } } }