結果

問題 No.767 配られたジャパリまん
ユーザー chonbo0127chonbo0127
提出日時 2021-08-04 12:17:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,893 ms / 2,000 ms
コード長 1,752 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 259,848 KB
最終ジャッジ日時 2023-10-14 21:15:21
合計ジャッジ時間 6,666 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,348 KB
testcase_01 AC 77 ms
71,288 KB
testcase_02 AC 78 ms
71,196 KB
testcase_03 AC 78 ms
71,196 KB
testcase_04 AC 127 ms
77,928 KB
testcase_05 AC 283 ms
110,252 KB
testcase_06 AC 74 ms
71,380 KB
testcase_07 AC 77 ms
71,488 KB
testcase_08 AC 81 ms
76,128 KB
testcase_09 AC 129 ms
83,884 KB
testcase_10 AC 197 ms
94,004 KB
testcase_11 AC 155 ms
96,180 KB
testcase_12 AC 152 ms
89,304 KB
testcase_13 AC 188 ms
91,416 KB
testcase_14 AC 149 ms
98,864 KB
testcase_15 AC 109 ms
100,992 KB
testcase_16 AC 155 ms
93,184 KB
testcase_17 AC 90 ms
82,472 KB
testcase_18 AC 91 ms
83,620 KB
testcase_19 AC 164 ms
101,884 KB
testcase_20 AC 1,893 ms
259,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W,K = map(int,input().split())
L = [list(map(int,input().split())) for _ in range(K)]
L = [L[i][0]*(W+1)+L[i][1] for i in range(K)]
MOD = 10**8+7

factorial = [1, 1]
inverse = [1, 1]
invere_base = [0, 1]
for i in range(2, H+W + 1):
    factorial.append((factorial[-1] * i) % MOD)
    invere_base.append((-invere_base[MOD % i] * (MOD // i)) % MOD) #逆元
    inverse.append((inverse[-1] * invere_base[-1]) % MOD) #階乗逆元

def nCr(n, r):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return factorial[n] * inverse[r] * inverse[n - r] % MOD

def bit_count(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c

D = [0]*(1<<K)
for i in range(1<<K):
    X = []
    for j in range(K):
        if i&(1<<j):
            X.append(L[j])
    X.sort()
    lx = len(X)
    a,b = 0,0
    ans = 1
    for j in range(lx):
        na,nb = divmod(X[j],W+1)
        da,db = na-a,nb-b
        ans *= nCr(da+db,db)
        ans %= MOD
        a,b = na,nb
    na,nb = H,W
    da,db = na-a,nb-b
    ans *= nCr(da+db,db)
    ans %= MOD
    if bit_count(i)%2:
        ans *= -1
    D[i] = ans%MOD

dp = [D[i] for i in range(1<<K)]
for j in range(K):
    ndp = [0]*(1<<K)
    for i in range(1<<K):
        if i&(1<<j):
            ndp[i] = dp[i]+dp[i&(~(1<<j))]
        else:
            ndp[i] = dp[i]
        ndp[i] %= MOD
    dp = ndp[:]

for i in range(1<<K):
    print(dp[i])
0