結果

問題 No.1141 田グリッド
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-01 00:44:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,285 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 85,572 KB
実行使用メモリ 6,280 KB
最終ジャッジ日時 2023-09-21 04:25:59
合計ジャッジ時間 5,368 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 153 ms
4,376 KB
testcase_14 AC 163 ms
6,280 KB
testcase_15 AC 147 ms
4,376 KB
testcase_16 AC 147 ms
4,380 KB
testcase_17 AC 149 ms
4,380 KB
testcase_18 AC 148 ms
4,380 KB
testcase_19 AC 147 ms
4,376 KB
testcase_20 AC 146 ms
4,376 KB
testcase_21 AC 150 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 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 <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;
long long pow(long long a, long long n, long long p) {
    long 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 long>> a(h, vector<long long>(w,0));

    long 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 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;
        }
    }

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


    int q;
    cin >> q;
    for (int i=0; i<q; i++) {
        int r,c;
        cin >> r >> c;
        long 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