結果

問題 No.1141 田グリッド
ユーザー sbitesbite
提出日時 2020-07-31 22:57:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,947 bytes
コンパイル時間 2,475 ms
コンパイル使用メモリ 207,124 KB
実行使用メモリ 8,596 KB
最終ジャッジ日時 2023-09-21 01:49:48
合計ジャッジ時間 7,969 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,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 190 ms
5,276 KB
testcase_14 AC 212 ms
8,596 KB
testcase_15 AC 196 ms
4,988 KB
testcase_16 AC 195 ms
5,052 KB
testcase_17 AC 196 ms
5,156 KB
testcase_18 AC 193 ms
4,988 KB
testcase_19 AC 195 ms
5,008 KB
testcase_20 AC 194 ms
5,032 KB
testcase_21 AC 196 ms
4,960 KB
testcase_22 AC 198 ms
4,956 KB
testcase_23 AC 197 ms
4,996 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>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

ll mpow(ll base, ll num)
{
    if (num <= 0)
        return 1;
    ll prev = mpow(base, num / 2);
    if (num % 2 == 0)
    {
        return (prev * prev) % MOD;
    }
    else
    {
        return (((prev * prev) % MOD) * base) % MOD;
    }
}

ll inv(ll num)
{
    return mpow(num, MOD - 2);
}

int main()
{
    ll h, w;
    cin >> h >> w;
    VVL g(h, VL(w, 0));
    rep(i, h) rep(j, w) cin >> g[i][j];

    VVL multi(h + 1, VL(w + 1, 1));

    rep(i, h) multi[i + 1][1] = (multi[i][1] * g[i][0]) % MOD;
    rep(i, w) multi[1][i + 1] = (multi[1][i] * g[0][i]) % MOD;
    rep(i, 1, h)
    {
        rep(j, 1, w)
        {
            //multi[i + 1][j + 1] = mpow(multi[i][j + 1] * multi[i + 1][j], multi[i][j] - 2) * g[i][j];
            multi[i + 1][j + 1] = (((((multi[i][j + 1] * multi[i + 1][j]) % MOD) * inv(multi[i][j])) % MOD) * g[i][j]) % MOD;

            multi[i + 1][j + 1] %= MOD;
        }
    }

    ll total = multi[h][w];
    int q;
    cin >> q;
    rep(i, q)
    {
        int x, y;
        cin >> y >> x;
        ll tmp = multi[y][w] * inv(multi[y - 1][w]);
        tmp %= MOD;

        tmp *= (multi[h][x] * inv(multi[h][x - 1])) % MOD;
        tmp %= MOD;

        tmp *= inv(g[y - 1][x - 1]);
        tmp %= MOD;

        cout << (total * inv(tmp)) % MOD << endl;
    }

    return 0;
}
0