結果

問題 No.1141 田グリッド
ユーザー yakkiyakki
提出日時 2020-07-31 22:16:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,891 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 128,072 KB
実行使用メモリ 8,884 KB
最終ジャッジ日時 2023-09-20 23:49:49
合計ジャッジ時間 8,068 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 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 5 ms
4,384 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 RE -
testcase_14 AC 234 ms
8,884 KB
testcase_15 AC 228 ms
4,540 KB
testcase_16 AC 225 ms
4,572 KB
testcase_17 AC 224 ms
4,652 KB
testcase_18 AC 223 ms
4,636 KB
testcase_19 AC 225 ms
4,584 KB
testcase_20 AC 223 ms
4,816 KB
testcase_21 AC 225 ms
4,508 KB
testcase_22 AC 226 ms
4,604 KB
testcase_23 AC 225 ms
4,536 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1)
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll 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<int>> a(h,vector<int>(w));
    rep(i,h)rep(j,w) cin >> a[i][j];
    int q; cin >> q;
    vector<vector<ll>> seki(h+1,vector<ll>(w+1));
    rep(i,h+1) seki[i][0] = 1;
    rep(i,w+1) seki[0][i] = 1;
    rep(i,h)rep(j,w){
        seki[i+1][j+1] = (a[i][j] == 0 ? 1:a[i][j])*seki[i+1][j]%MOD*seki[i][j+1]%MOD*modinv(seki[i][j],MOD)%MOD;
    }
    vector<int> h0(h),w0(h);
    int cnt = 0;
    rep(i,h){
        rep(j,w){
            if(a[i][j] == 0){
                h0[i]++;
                cnt++;
            }
        }
    }
    rep(i,w){
        rep(j,h){
            if(a[j][i] == 0){
                w0[i]++;
                cnt++;
            }
        }
    }
    while(q--){
        int r,c; cin >> r >> c;
        r--; c--;
        ll ans = seki[h][w]*modinv(seki[r+1][w]*modinv(seki[r][w],MOD)%MOD,MOD)%MOD*modinv(seki[h][c+1]*modinv(seki[h][c]%MOD,MOD),MOD)%MOD*a[r][c]%MOD;
        if(cnt-h0[r]-w0[c] > 0) cout << 0 << endl;
        else cout << ans << endl;
    }
}
0