結果

問題 No.1141 田グリッド
ユーザー hs0319boyhs0319boy
提出日時 2020-07-31 23:01:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,877 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 178,620 KB
実行使用メモリ 6,864 KB
最終ジャッジ日時 2023-09-21 02:02:33
合計ジャッジ時間 6,746 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 161 ms
5,108 KB
testcase_14 AC 171 ms
6,864 KB
testcase_15 AC 158 ms
4,608 KB
testcase_16 AC 158 ms
4,464 KB
testcase_17 AC 159 ms
4,620 KB
testcase_18 AC 155 ms
4,468 KB
testcase_19 AC 155 ms
4,456 KB
testcase_20 AC 155 ms
4,620 KB
testcase_21 AC 158 ms
4,396 KB
testcase_22 AC 158 ms
4,600 KB
testcase_23 AC 156 ms
4,584 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
    set<int> zerorow,zerocolumn;
    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.insert(i);
            zerocolumn.insert(j);
            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){
             if(!((!zerorow.size()||zerorow.size()==1&&zerorow.count(r))&&(!zerocolumn.size()||zerocolumn.size()==1&&zerocolumn.count(c)))){
                 ans.push_back(0);
                 continue;
             }
        }
        tmp=ap*row[r];tmp%=inf;
        tmp*=column[c];tmp%=inf;
        tmp*=a[r][c];tmp%=inf;
        ans.push_back(tmp);
    }
    rep(i,ans.size())cout<<ans[i]<<endl;
}
0