結果

問題 No.767 配られたジャパリまん
ユーザー pekempeypekempey
提出日時 2018-12-15 03:25:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 1,991 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 46,904 KB
実行使用メモリ 9,716 KB
最終ジャッジ日時 2023-10-25 10:43:07
合計ジャッジ時間 2,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,716 KB
testcase_01 AC 7 ms
9,716 KB
testcase_02 AC 7 ms
9,716 KB
testcase_03 AC 7 ms
9,716 KB
testcase_04 AC 8 ms
9,716 KB
testcase_05 AC 27 ms
9,716 KB
testcase_06 AC 7 ms
9,716 KB
testcase_07 AC 7 ms
9,716 KB
testcase_08 AC 7 ms
9,716 KB
testcase_09 AC 7 ms
9,716 KB
testcase_10 AC 17 ms
9,716 KB
testcase_11 AC 7 ms
9,716 KB
testcase_12 AC 7 ms
9,716 KB
testcase_13 AC 17 ms
9,716 KB
testcase_14 AC 7 ms
9,716 KB
testcase_15 AC 7 ms
9,716 KB
testcase_16 AC 7 ms
9,716 KB
testcase_17 AC 7 ms
9,716 KB
testcase_18 AC 6 ms
9,716 KB
testcase_19 AC 8 ms
9,716 KB
testcase_20 AC 357 ms
9,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>

#define M 100000007

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) {
    a.n += b.n;
    if (a.n >= M) {
        a.n -= M;
    }
    return a;
}

mint operator-(mint a, mint b) {
    a.n -= b.n;
    if (a.n < 0) {
        a.n += M;
    }
    return a;
}

mint operator*(mint a, mint b) {
    return (long long)a.n * b.n % M;
}

mint &operator-=(mint &a, mint b) {
    return a = a - b;
}

mint &operator*=(mint &a, mint b) {
    return a = a * b;
}

mint fact[200001] = {1,1};
mint ifact[200001] = {1,1};
mint inv[200001] = {0,1};

void init() {
    for (int i = 2; i <= 200000; i++) {
        inv[i] = inv[M % i] * (M - M / i);
        fact[i] = fact[i - 1] * i;
        ifact[i] = ifact[i - 1] * inv[i];
    }
}

mint C(int n, int r) {
    if (n < 0 || r < 0 || n < r) return 0;
    return fact[n] * ifact[n - r] * ifact[r];
}

int H, W, K, Y[20], X[20], P[20];
mint ans[1 << 20];

int main() {
    init();
    scanf("%d %d %d", &H, &W, &K);
    for (int i = 0; i < K; i++) {
        scanf("%d %d", Y + i, X + i);
        P[i] = i;
    }
    std::sort(P, P + K, [&](int i, int j) { return Y[i] + X[i] < Y[j] + X[j]; });
    for (int i = 0; i < 1 << K; i++) {
        int y = 0;
        int x = 0;
        ans[i] = 1;
        for (int j = 0; j < K; j++) if (i >> P[j] & 1) {
            int dy = Y[P[j]] - y;
            int dx = X[P[j]] - x;
            ans[i] *= C(dy + dx, dx);
            y = Y[P[j]];
            x = X[P[j]];
        }
        int dy = H - y;
        int dx = W - x;
        ans[i] *= C(dy + dx, dx);
    }
    /* moebius transform */
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < 1 << K; j++) {
            if (~j & 1 << i) {
                ans[j | 1 << i] -= ans[j];
            }
        }
    }
    for (int i = 0; i < 1 << K; i++) {
        for (int j = 0; j < K; j++) if (i >> j & 1) ans[i] *= M - 1;
        printf("%d\n", ans[i].n);
    }
    return 0;
}

0