結果

問題 No.1141 田グリッド
ユーザー firiexp
提出日時 2020-07-31 21:52:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 3,269 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 109,972 KB
最終ジャッジ日時 2025-01-12 09:53:59
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:70:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   70 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~
main.cpp:98:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   98 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template<u32 M = 1000000007>
struct modint{
u32 val;
modint(): val(0){}
template<typename T>
modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}
modint pow(ll k) const {
modint res(1), x(val);
while(k){
if(k&1) res *= x;
x *= x;
k >>= 1;
}
return res;
}
template<typename T>
modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
modint inv() const {return pow(M-2);}
modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
modint& operator/=(modint a){return (*this) *= a.inv();}
modint operator+(modint a) const {return modint(val) +=a;}
modint operator-(modint a) const {return modint(val) -=a;}
modint operator*(modint a) const {return modint(val) *=a;}
modint operator/(modint a) const {return modint(val) /=a;}
modint operator-(){return modint(M-val);}
bool operator==(const modint a) const {return val == a.val;}
bool operator!=(const modint a) const {return val != a.val;}
bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }
template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }
template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }
int main() {
int h, w;
cin >> h >> w;
auto v = make_v(h+1, w+1, mint(1));
auto z = make_v(h+1, w+1, 0);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
int x;
scanf("%d", &x);
if(x) v[i+1][j+1] = x;
else {
v[i+1][j+1] = 1;
z[i+1][j+1] = 1;
}
}
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j <= w; ++j) {
v[i+1][j] *= v[i][j];
z[i+1][j] += z[i][j];
}
}
for (int i = 0; i <= h; ++i) {
for (int j = 0; j < w; ++j) {
v[i][j+1] *= v[i][j];
z[i][j+1] += z[i][j];
}
}
auto f = [&](int x1, int y1, int x2, int y2) -> mint {
if(z[x2][y2] - z[x1][y2] - z[x2][y1] + z[x1][y1]) return 0;
else return v[x2][y2]*v[x1][y1]/(v[x1][y2]*v[x2][y1]);
};
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int a, b;
scanf("%d %d", &a, &b);
a--; b--;
cout << (f(0, 0, a, b)*f(a+1, 0, h, b)*f(0, b+1, a, w)*f(a+1, b+1, h, w)).val << "\n";
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0