結果

問題 No.1141 田グリッド
ユーザー DriceDrice
提出日時 2020-07-31 22:35:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,545 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 33,472 KB
実行使用メモリ 4,408 KB
最終ジャッジ日時 2023-09-21 01:05:20
合計ジャッジ時間 2,860 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 46 ms
4,408 KB
testcase_14 AC 45 ms
4,408 KB
testcase_15 AC 43 ms
4,376 KB
testcase_16 AC 43 ms
4,376 KB
testcase_17 AC 42 ms
4,380 KB
testcase_18 AC 24 ms
4,380 KB
testcase_19 AC 24 ms
4,380 KB
testcase_20 AC 24 ms
4,376 KB
testcase_21 AC 44 ms
4,380 KB
testcase_22 AC 43 ms
4,376 KB
testcase_23 AC 43 ms
4,380 KB
testcase_24 AC 25 ms
4,376 KB
testcase_25 AC 25 ms
4,376 KB
testcase_26 AC 24 ms
4,376 KB
testcase_27 AC 24 ms
4,380 KB
testcase_28 AC 26 ms
4,376 KB
testcase_29 AC 24 ms
4,376 KB
testcase_30 AC 24 ms
4,376 KB
testcase_31 AC 25 ms
4,380 KB
testcase_32 AC 25 ms
4,376 KB
testcase_33 AC 25 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
const long long mod = 1e9+7;
long long a[100005];
long long row[100005], col[100005];
int cntR[100005], cntC[100005];

long long getElement(int i,int j,int n,int m){
    int id = (i-1)*m+j;
    return a[id];
}

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

long long inv(long long u){ return power(u,mod-2); }

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) row[i] = 1, cntR[i] = 0;
    for(int i = 1; i <= m; i++) col[i] = 1, cntC[i] = 0;
    long long all = 1; int cnt = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            int id = (i-1)*m+j;
            scanf("%lld",&a[id]);
            if(a[id]==0){
                cntR[i]++;
                cntC[j]++;
                cnt++;
            }
            else{
                row[i] = row[i]*a[id]%mod;
                col[j] = col[j]*a[id]%mod;
                all = all*a[id]%mod;
            }
        }
    }
    int q;
    scanf("%d",&q);
    while(q--){
        int r,c;
        scanf("%d%d",&r,&c);
        int leftCnt = cnt-cntR[r]-cntC[c];
        if(getElement(r,c,n,m)==0) leftCnt++;
        if(leftCnt==0){
            long long res = all*inv(row[r])%mod*inv(col[c])%mod;
            long long middle = getElement(r,c,n,m);
            if(middle!=0) res = res*middle%mod;
            printf("%lld\n",res);
        }
        else printf("0\n");
    }
    return 0;
}
0