結果

問題 No.1141 田グリッド
ユーザー merom686merom686
提出日時 2020-07-31 21:49:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,492 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 87,384 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-20 22:50:23
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 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 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 22 ms
4,376 KB
testcase_19 AC 22 ms
4,376 KB
testcase_20 AC 22 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 22 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 22 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll modinv(int n) {
    int m = P, y = 0, v = 1;
    while (1) {
        int q = m / n;
        int r = m % n;
        if (r == 0) return v < 0 ? v + P : v;
        y -= v * q;
        swap(y, v);
        m = n;
        n = r;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w;
    cin >> h >> w;

    vector<int> x(h), y(w, 1), z(h * w);
    vector<int> x0(h), y0(w, 0);
    ll s = 1;
    int s0 = 0;

    for (int i = 0; i < h; i++) {
        ll t = 1;
        int t0 = 0;
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;

            z[i * w + j] = a;
            if (a == 0) {
                t0++;
                y0[j]++;
            } else {
                (t *= a) %= P;
                y[j] = y[j] * a % P;
            }
        }
        x[i] = t;
        x0[i] = t0;
        (s *= t) %= P;
        s0 += t0;
    }

    int q;
    cin >> q;

    while (q--) {
        int i, j;
        cin >> i >> j;
        i--; j--;

        int a = z[i * w + j];
        if (s0 - x0[i] - y0[j] + (a == 0) == 0) {
            int r = s * modinv((ll)x[i] * y[j] % P) % P;
            if (a != 0) r = (ll)r * a % P;
            cout << r << '\n';
        } else {
            cout << 0 << '\n';
        }
    }

    return 0;
}
0