結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
pitsu_kyo_pro
|
| 提出日時 | 2020-07-31 22:57:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,569 bytes |
| コンパイル時間 | 929 ms |
| コンパイル使用メモリ | 110,048 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 20:33:50 |
| 合計ジャッジ時間 | 3,217 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 10 |
ソースコード
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime mod
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
// mint N;
//cout << N.x << endl;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H,W;
cin >> H >> W;
vector<vector<mint>> G(H,vector<mint>(W,1));
vector<bool> H_0(H,false),W_0(W,false);
mint all = 1;
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
int a;
cin >> a;
if(a == 0){
H_0[i] = true;
W_0[j] = true;
continue;
}
G[i][j] = a;
all *= a;
}
}
bool can = true;
int pos_H=-1,pos_W=-1;
vector<mint> sum_H(H,1);
for(int i=0; i<H; i++){
if(H_0[i]){
if(pos_H != -1){
can = false;
}else{
pos_H = i;
}
}
for(int j=0; j<W; j++){
sum_H[i] *= G[i][j];
}
}
vector<mint> sum_W(W,1);
for(int i=0; i<W; i++){
if(W_0[i]){
if(pos_W != -1){
can = false;
}else{
pos_W = i;
}
}
for(int j=0; j<H; j++){
sum_W[i] *= G[j][i];
}
}
int Q;
cin >> Q;
for(int i=0; i<Q; i++){
int r,c;
cin >> r >> c;
r--;c--;
if(!can){
cout << 0 << "\n";
continue;
}
if(pos_H != -1 && pos_H != r){
cout << 0 << "\n";
continue;
}
if(pos_W != -1 && pos_W != c){
cout << 0 << "\n";
continue;
}
cout << (all/sum_H[r]/sum_W[c]*G[r][c]).x << "\n";
}
return 0;
}
pitsu_kyo_pro