結果

問題 No.1141 田グリッド
ユーザー Sooh31Sooh31
提出日時 2020-07-31 23:11:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,231 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 170,440 KB
実行使用メモリ 6,184 KB
最終ジャッジ日時 2023-09-21 02:24:03
合計ジャッジ時間 6,880 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 165 ms
4,376 KB
testcase_14 AC 177 ms
6,184 KB
testcase_15 AC 163 ms
4,376 KB
testcase_16 AC 163 ms
4,380 KB
testcase_17 AC 159 ms
4,376 KB
testcase_18 AC 154 ms
4,376 KB
testcase_19 AC 155 ms
4,428 KB
testcase_20 AC 154 ms
4,380 KB
testcase_21 AC 161 ms
4,380 KB
testcase_22 AC 163 ms
4,380 KB
testcase_23 AC 162 ms
4,380 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;

const ll mod = 1000000007;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long 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;
    vector<vector<ll>> mp(h, vector<ll>(w));
    vector<ll> preh(h);
    vector<ll> prew(w);
    ll ans = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mp[i][j];
            ans = ans * mp[i][j] % mod;
        }
    }
    for(int i = 0; i < h; i++){
        preh[i] = 1;
        for(int j = 0; j < w; j++){
            preh[i] *= mp[i][j];
            preh[i] %= mod;
        }
    }
    for(int i = 0; i < w; i++){
        prew[i] = 1;
        for(int j = 0; j < h; j++){
            prew[i] *= mp[j][i];
            prew[i] %= mod;
        }
    }
    int q; cin >> q;
    while(q--){
        int r, c; cin >> r >> c;
        r--; c--;
        ll a = modinv(preh[r], mod); ll b = modinv(prew[c], mod);
        ll ans1 = ans * a % mod * b % mod * mp[r][c] % mod; 
        cout << ans1 << endl;
    }
}
0