結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
shimarut
|
| 提出日時 | 2021-03-28 18:41:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,966 bytes |
| コンパイル時間 | 3,131 ms |
| コンパイル使用メモリ | 189,804 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-29 09:19:03 |
| 合計ジャッジ時間 | 7,349 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 10 |
ソースコード
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>
#include <fstream>
#include <array>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
//using mint = modint998244353;
//using mint = modint;
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vmint = vector<mint>;
using vvmint = vector<vmint>;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#pragma region UnionFind
struct UnionFind
{
vector<int> par;
UnionFind(int n) : par(n, -1) {}
void init(int n) { par.assign(n, -1); }
int root(int x)
{
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
bool merge(int x, int y)
{
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x)
{
return -par[root(x)];
}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
if (b == 0)return a;
return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
#pragma endregion
#pragma region グリッド内チェック
bool out(int x, int y, int h, int w)
{
if (x < 0 || h <= x || y < 0 || w <= y)return true;
else return false;
}
#pragma endregion
#pragma region Dijkstra
vl dijkstra(vector<vector<pair<int, ll>>> v, int s)
{
ll INF = 1e18;
int MAX = 1e6;
vl res(MAX, INF);
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
q.push({ 0,s });
while (!q.empty())
{
int now;
ll d;
tie(d, now) = q.top();
q.pop();
if (!chmin(res[now], d))continue;
for (auto p : v[now])
{
int next;
ll c;
tie(next, c) = p;
if (res[next] <= res[now] + c)continue;
q.push({ res[now] + c,next });
}
}
return res;
}
#pragma endregion
#pragma endregion
int main()
{
int h, w; cin >> h >> w;
bool includes_zero = false;
vvl a(h, vl(w));
rep(i, h)rep(j, w)
{
cin >> a[i][j];
if (a[i][j] == 0)includes_zero = true;
}
if (!includes_zero)
{
vmint rs(h), cs(w);
mint s = 1;
rep(i, h)rep(j, w)s *= a[i][j];
rep(i, h)
{
mint t = 1;
rep(j, w)t *= a[i][j];
rs[i] = t;
}
rep(i, w)
{
mint t = 1;
rep(j, h)t *= a[j][i];
cs[i] = t;
}
int q; cin >> q;
while (q--)
{
int r, c; cin >> r >> c;
--r, --c;
mint res = s;
res *= a[r][c];
res /= rs[r];
res /= cs[c];
cout << res.val() << endl;
}
}
else
{
vvi zero(h, vi(w));
int zero_cnt = 0;
rep(i, h)rep(j, w)if (a[i][j] == 0)
{
zero[i][j] = 1;
++zero_cnt;
}
vi r_zero(h), c_zero(w);
rep(i, h)
{
int cnt = 0;
rep(j, w)if (a[i][j] == 0)++cnt;
r_zero[i] = cnt;
}
rep(i, w)
{
int cnt = 0;
rep(j, h)if (a[j][i] == 0)++cnt;
c_zero[i] = cnt;
}
mint s = 1;
rep(i, h)rep(j, w)if (r_zero[i] == 0 && c_zero[j] == 0)s *= a[i][j];
int q; cin >> q;
while (q--)
{
int r, c; cin >> r >> c;
--r, --c;
int z = r_zero[r] + c_zero[c] - zero[r][c];
if (z == zero_cnt)cout << s.val() << endl;
else cout << 0 << endl;
}
}
}
shimarut