結果

問題 No.1141 田グリッド
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-01 00:43:15
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,349 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 86,448 KB
実行使用メモリ 6,600 KB
最終ジャッジ日時 2023-09-21 04:25:27
合計ジャッジ時間 5,893 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 RE -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 RE -
testcase_14 AC 287 ms
6,600 KB
testcase_15 AC 149 ms
4,380 KB
testcase_16 AC 146 ms
4,380 KB
testcase_17 AC 150 ms
4,376 KB
testcase_18 AC 147 ms
4,380 KB
testcase_19 AC 145 ms
4,376 KB
testcase_20 AC 144 ms
4,380 KB
testcase_21 AC 147 ms
4,376 KB
testcase_22 AC 148 ms
4,376 KB
testcase_23 AC 147 ms
4,376 KB
testcase_24 WA -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 RE -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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 % MOD;
}

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