結果

問題 No.1141 田グリッド
ユーザー kyort0nkyort0n
提出日時 2020-07-31 21:41:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 2,457 bytes
コンパイル時間 1,858 ms
コンパイル使用メモリ 176,368 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 17:09:50
合計ジャッジ時間 5,644 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long long INF = 1e18;
const ll mod = 1000000007;
ll H, W, Q;
vector<ll> inv, FactorialInv, Factorial;
ll beki(ll a, ll b){
ll ret = 1 % mod;
a %= mod;
while(b) {
if(b & 1LL) ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
void init_combination(ll MAX){
Factorial.resize(MAX + 1);
FactorialInv.resize(MAX + 1);
inv.resize(MAX + 1);
Factorial[0] = 1;
inv[0] = 1;
for(int i = 1; i <= MAX; i++){
Factorial[i] = Factorial[i - 1] * i % mod;
}
FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
for(ll i = MAX - 1; i >= 0; i--) {
FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
}
for(int i = 1; i <= MAX; i++) {
inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
}
}
ll combination(ll a, ll b){
if((a == b) || (b == 0)){
return 1;
}
if(a < b) return 0;
if(b < 0) return 0;
ll ans = Factorial[a] * FactorialInv[b] % mod;
ans = ans * FactorialInv[a - b] % mod;
return ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> H >> W;
vector<vector<ll>> A(H, vector<ll>(W));
vector<ll> row(H, 1), column(W, 1), zerorow(H, 0), zerocolumn(W, 0);
ll prod = 1;
ll zero = 0;
for(int h = 0; h < H; h++) {
for(int w = 0; w < W; w++) {
cin >> A[h][w];
if(A[h][w]) row[h] = row[h] * A[h][w] % mod;
else zerorow[h]++;
if(A[h][w]) column[w] = column[w] * A[h][w] % mod;
else zerocolumn[w]++;
if(A[h][w]) prod = prod * A[h][w] % mod;
else zero++;
}
}
cin >> Q;
while(Q--) {
int h, w;
cin >> h >> w;
h--;
w--;
ll ans = prod;
ans = ans * beki(row[h], mod - 2) % mod;
ans = ans * beki(column[w], mod - 2) % mod;
if(A[h][w]) ans = ans * A[h][w] % mod;
ll tmp = zerorow[h] + zerocolumn[w];
if(A[h][w] == 0) tmp--;
if(tmp != zero) ans = 0;
cout << ans << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0