結果

問題 No.767 配られたジャパリまん
ユーザー ayaoniayaoni
提出日時 2021-08-04 04:17:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,541 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 86,788 KB
実行使用メモリ 107,120 KB
最終ジャッジ日時 2023-10-14 21:12:34
合計ジャッジ時間 5,584 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,224 KB
testcase_01 AC 72 ms
71,152 KB
testcase_02 AC 74 ms
71,256 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 74 ms
71,316 KB
testcase_07 WA -
testcase_08 AC 78 ms
76,056 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 #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


H,W,k = MI()
mod = 10**8+7
friends = []
for _ in range(k):
    a,b = MI()
    friends.append((W+1)*a+b)

fac = [1]
for i in range(1,H+W+1):
    fac.append((fac[-1]*i) % mod)
fac_inv = [0]*(H+W+1)
f = pow(fac[-1],mod-2,mod)
for i in range(H+W,-1,-1):
    fac_inv[i] = f
    f *= i
    f %= mod


def comb(n,r):
    return fac[n] * fac_inv[r] % mod * fac_inv[n-r] % mod


K = 1 << k
F = [0]*K
for i in range(K):
    X = [0]
    for j in range(k):
        if not (i >> j) & 1:
            X.append(friends[j])
    X.append((W+1)*H+W)

    f = 1
    for j in range(len(X)-1):
        a0,b0 = divmod(X[j],W+1)
        a1,b1 = divmod(X[j+1],W+1)
        if a0 > a1 or b0 > b1:
            break
        f *= comb((a1-a0)+(b1-b0),a1-a0)
        f %= mod
    else:
        F[i] = f


def mobius_transform(F,n):
    # res[i] = (iを含む集合jに対する (-1)^(#j-#i)F[j] の和)
    N = 1 << n
    res = F[:]
    for i in range(n):
        k = 1 << i
        for j in range(N):
            if not j & k:
                res[j] -= res[j^k]
    return res


G = mobius_transform(F,k)[::-1]
for g in G:
    print(abs(g) % mod)
0