結果

問題 No.1141 田グリッド
コンテスト
ユーザー zeronosu77108
提出日時 2020-08-01 00:40:30
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,343 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 122,752 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 23:01:25
合計ジャッジ時間 5,656 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 RE * 1
other AC * 20 WA * 6 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;
long pow(long a, long n, long p) {
    long res = 1;
    while(n!=0) {
        if (n%2) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= p;
        n >>= 1;
    }
    return res;
}

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<long>> a(h, vector<long>(w,0));

    long cpro = 1;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> a[i][j];
            cpro *= a[i][j];
            cpro %= MOD;
        }
    }

    vector<long> hpro(h,1);
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            hpro[i] *= a[i][j];
            hpro[i] %= MOD;
        }
    }

    for (int i=0; i<h; i++) cerr<<hpro[i]<<" ";cerr<<endl;

    vector<long> wpro(h,1);
    for (int i=0; i<w; i++) {
        for (int j=0; j<h; j++) {
            wpro[i] *= a[j][i];
            wpro[i] %= MOD;
        }
    }

    for (int i=0; i<w; i++) cerr<<wpro[i]<<" ";cerr<<endl;

    int q;
    cin >> q;
    for (int i=0; i<q; i++) {
        int r,c;
        cin >> r >> c;
        long ans = cpro;
        (ans *= pow(hpro[r-1], MOD-2, MOD)) %= MOD;
        (ans *= pow(wpro[c-1], MOD-2, MOD)) %= MOD;
        (ans *= a[r-1][c-1]) %= MOD;
        cout << ans << endl;
    }
}
0