結果

問題 No.767 配られたジャパリまん
ユーザー PachicobuePachicobue
提出日時 2018-12-15 00:31:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,215 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 213,408 KB
実行使用メモリ 8,056 KB
最終ジャッジ日時 2023-10-25 10:30:51
合計ジャッジ時間 4,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,348 KB
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 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
constexpr ll MOD = 100000007;
template <ll mod = MOD>
class ModCombination
{
public:
    ModCombination(const std::size_t n) : fact(n + 1, 1), inv(n + 1, 1), inv_fact(n + 1, 1)
    {
        for (ll i = 2; i <= (ll)n; i++) { fact[i] = (fact[i - 1] * i) % mod, inv[i] = ((mod - (mod / i)) * inv[mod % i]) % mod, inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod; }
    }
    ll factorial(const std::size_t n) const { return fact[n]; }
    ll inverse(const std::size_t n) const { return inv[n]; }
    ll inverseFactorial(const std::size_t n) const { return inv_fact[n]; }
    ll permutation(const std::size_t n, const std::size_t k) const { return (fact[n] * inv_fact[n - k]) % mod; }
    ll combination(const std::size_t n, const std::size_t k) const { return (((fact[n] * inv_fact[k]) % mod) * inv_fact[n - k]) % mod; }

private:
    std::vector<ll> fact, inv, inv_fact;
};
int main()
{
    int H, W, K;
    std::cin >> H >> W >> K;
    ModCombination<> mod(H + W);
    std::vector<int> a(K + 2), b(K + 2);
    a[0] = b[0] = 0, a[K + 1] = H, b[K + 1] = W;
    for (int i = 1; i <= K; i++) { std::cin >> a[i] >> b[i]; }
    std::vector<std::vector<ll>> d(K + 2, std::vector<ll>(K + 2, 0));
    for (int i = 0; i < K + 2; i++) {
        for (int j = 0; j < K + 2; j++) {
            if (a[i] <= a[j] and b[i] <= b[j]) { d[i][j] = mod.combination(a[j] + b[j] - a[i] - b[i], a[j] - a[i]); }
        }
    }
    std::vector<ll> memo(K + 2, -1);
    auto dp = [&](auto&& self, const int s) -> ll {
        if (memo[s] != -1) { return memo[s]; }
        ll ans = d[s][K + 1];
        for (int i = 0; i <= K; i++) {
            if (i == s or d[s][i] == 0) { continue; }
            const ll minus = d[s][i] * self(self, i) % MOD;
            (ans += (MOD - minus)) %= MOD;
        }
        return memo[s] = ans;
    };
    for (int q = 0; q < (1 << K); q++) {
        auto at = [&](const int j) -> bool { return ((q >> j) & 1) == 0; };
        ll ans = dp(dp, 0);
        for (int i = 1; i <= K; i++) {
            const int j = i - 1;
            if (at(j)) { (ans += dp(dp, i) * d[0][i] % MOD) %= MOD; }
        }
        std::cout << ans << std::endl;
    }

    return 0;
}
0