結果

問題 No.1141 田グリッド
ユーザー hs0319boyhs0319boy
提出日時 2020-07-31 23:14:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,894 bytes
コンパイル時間 1,735 ms
コンパイル使用メモリ 173,188 KB
実行使用メモリ 7,264 KB
最終ジャッジ日時 2023-09-21 02:37:51
合計ジャッジ時間 6,851 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 161 ms
5,272 KB
testcase_14 AC 168 ms
7,264 KB
testcase_15 AC 159 ms
4,608 KB
testcase_16 AC 160 ms
4,620 KB
testcase_17 AC 155 ms
4,548 KB
testcase_18 AC 154 ms
4,420 KB
testcase_19 AC 155 ms
4,408 KB
testcase_20 AC 154 ms
4,540 KB
testcase_21 AC 159 ms
4,456 KB
testcase_22 AC 159 ms
4,596 KB
testcase_23 AC 158 ms
4,440 KB
testcase_24 AC 154 ms
4,392 KB
testcase_25 AC 160 ms
4,460 KB
testcase_26 AC 158 ms
4,796 KB
testcase_27 AC 158 ms
4,468 KB
testcase_28 AC 160 ms
4,624 KB
testcase_29 AC 158 ms
4,536 KB
testcase_30 AC 158 ms
4,608 KB
testcase_31 AC 156 ms
4,396 KB
testcase_32 AC 157 ms
4,500 KB
testcase_33 AC 157 ms
4,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

ll mondiv(ll a,ll m=inf){
    ll b=m;ll u=1;ll v=0;
    while(b){
        ll t=a/b;
        a-=t*b;swap(a,b);
        u-=t*v;swap(u,v);
    }
    u%=m;
    if(u<0)u+=m;
    return u;
}

int main(){
    int h,w;cin>>h>>w;
    vvll a(h,vll(w));
    vll row(h,(ll)1),column(w,(ll)1);
    vin zerorow(h),zerocolumn(w);
    ll allzero=(ll)0;
    bool zero=false;
    ll ap=(ll)1;ll tmp;
    rep(i,h)rep(j,w){
        cin>>a[i][j];
        if(a[i][j]==0){
            zerorow[i]++;
            zerocolumn[j]++;
            allzero++;
            zero=true;
            continue;
        }
        ap*=a[i][j];ap%=inf;
        tmp=mondiv(a[i][j]);
        row[i]*=tmp;row[i]%=inf;
        column[j]*=tmp;column[j]%=inf;
    }
    int q;cin>>q;
    vll ans;int r,c;
    rep(i,q){
        cin>>r>>c;r--;c--;
        if(zero){
             tmp=zerorow[r]+zerocolumn[c];
             if(a[r][c]==0)tmp--;
             if(tmp!=allzero){
                 ans.push_back(0);
                 continue;
             }
        }
        tmp=ap*row[r];tmp%=inf;
        tmp*=column[c];tmp%=inf;
        if(a[r][c]!=0)tmp*=a[r][c];tmp%=inf;
        ans.push_back(tmp);
    }
    rep(i,ans.size())cout<<ans[i]<<endl;
}
0