結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2020-07-31 21:44:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,489 bytes |
| コンパイル時間 | 1,059 ms |
| コンパイル使用メモリ | 94,244 KB |
| 最終ジャッジ日時 | 2025-01-12 09:42:06 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 21 |
ソースコード
#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] *= 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;
}
merom686