結果
| 問題 |
No.1141 田グリッド
|
| ユーザー |
mot
|
| 提出日時 | 2020-08-01 01:56:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 172 ms / 2,000 ms |
| コード長 | 1,852 bytes |
| コンパイル時間 | 803 ms |
| コンパイル使用メモリ | 84,368 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-07 00:40:26 |
| 合計ジャッジ時間 | 6,324 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
int H, W;
cin>>H>>W;
ll A[H][W];
ll sumA = 1;
ll tate[H], yoko[W];
int tatezero[H], yokozero[W];
int zeronum = 0;
for(int i=0;i<H;++i) {
tate[i] = 1;
tatezero[i] = 0;
}
for(int i=0;i<W;++i) {
yoko[i] = 1;
yokozero[i] = 0;
}
for(int i=0;i<H;++i) {
for(int j=0;j<W;++j) {
cin>>A[i][j];
if(A[i][j]==0) {
zeronum++;
tatezero[i]++;
yokozero[j]++;
continue;
}
sumA *= A[i][j];
sumA %= mod;
tate[i] *= A[i][j];
tate[i] %= mod;
yoko[j] *= A[i][j];
yoko[j] %= mod;
}
}
int Q;
cin>>Q;
int r, c;
ll tmp, tmpr, tmpc;
ll h, two;
for(int i=0;i<Q;++i) {
cin>>r>>c;
r--;
c--;
if(A[r][c]==0) {
if(tatezero[r]+yokozero[c]-1!=zeronum) {
cout<<0<<endl;
continue;
}
}
else {
if(tatezero[r]+yokozero[c]!=zeronum) {
cout<<0<<endl;
continue;
}
}
tmp = sumA;
if(A[r][c]>0) tmp *= A[r][c];
tmp %= mod;
h = mod - 2;
while(h>0) {
two = 1;
tmpr = tate[r];
tmpc = yoko[c];
while(2*two<h) {
two *= 2;
tmpr *= tmpr;
tmpr %= mod;
tmpc *= tmpc;
tmpc %= mod;
}
h -= two;
tmp *= tmpr;
tmp %= mod;
tmp *= tmpc;
tmp %= mod;
}
cout<<tmp<<endl;
}
}
mot