結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-31 22:27:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,046 bytes |
| コンパイル時間 | 3,152 ms |
| コンパイル使用メモリ | 200,476 KB |
| 最終ジャッジ日時 | 2025-01-12 10:41:44 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | int h,w; scanf("%d%d",&h,&w);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d",&B[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:61:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
61 | int q; scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:63:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | int i,j; scanf("%d%d",&i,&j); i--; j--;
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
class mint{
static const int MOD=1e9+7;
int x;
public:
mint():x(0){}
mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }
mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
mint& operator-=(const mint& m){ x-=m.x; if(x< 0) x+=MOD; return *this; }
mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
mint& operator/=(const mint& m){ return *this*=inverse(m); }
mint operator+(const mint& m)const{ return mint(*this)+=m; }
mint operator-(const mint& m)const{ return mint(*this)-=m; }
mint operator*(const mint& m)const{ return mint(*this)*=m; }
mint operator/(const mint& m)const{ return mint(*this)/=m; }
mint operator-()const{ return mint(-x); }
friend mint inverse(const mint& m){
int a=m.x,b=MOD,u=1,v=0;
while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
return u;
}
friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
int to_int()const{ return x; }
};
mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }
int main(){
int h,w; scanf("%d%d",&h,&w);
vector B(h,vector(w,0));
vector<int> row0,col0;
rep(i,h) rep(j,w) {
scanf("%d",&B[i][j]);
if(B[i][j]==0){
B[i][j]=1;
row0.emplace_back(i);
col0.emplace_back(j);
}
}
mint prod=1;
vector<mint> R(h,1),C(w,1);
rep(i,h) rep(j,w) {
prod*=B[i][j];
R[i]*=B[i][j];
C[j]*=B[i][j];
}
int q; scanf("%d",&q);
rep(_,q){
int i,j; scanf("%d%d",&i,&j); i--; j--;
if(row0.size()>=2 || col0.size()>=2){
puts("0");
}
else if((!row0.empty() && row0[0]!=i) || (!col0.empty() && col0[0]!=j)){
puts("0");
}
else{
printf("%d\n",(prod/(R[i]*C[j])*B[i][j]).to_int());
}
}
return 0;
}