結果

問題 No.767 配られたジャパリまん
ユーザー chonbo0127chonbo0127
提出日時 2021-08-04 12:26:00
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,785 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,456 KB
実行使用メモリ 260,324 KB
最終ジャッジ日時 2023-10-14 21:18:45
合計ジャッジ時間 6,947 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,716 KB
testcase_01 AC 71 ms
71,560 KB
testcase_02 AC 73 ms
71,480 KB
testcase_03 AC 72 ms
71,608 KB
testcase_04 AC 125 ms
78,284 KB
testcase_05 AC 314 ms
110,916 KB
testcase_06 AC 74 ms
71,648 KB
testcase_07 AC 73 ms
71,588 KB
testcase_08 AC 78 ms
76,228 KB
testcase_09 AC 128 ms
84,388 KB
testcase_10 AC 206 ms
94,460 KB
testcase_11 AC 157 ms
97,208 KB
testcase_12 AC 156 ms
90,192 KB
testcase_13 AC 191 ms
92,336 KB
testcase_14 AC 143 ms
99,248 KB
testcase_15 AC 104 ms
101,288 KB
testcase_16 AC 159 ms
94,032 KB
testcase_17 AC 85 ms
82,720 KB
testcase_18 AC 89 ms
84,072 KB
testcase_19 AC 158 ms
102,244 KB
testcase_20 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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) #階乗逆元

#combination
def nCr(n, r):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return factorial[n] * inverse[r] % MOD * 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][0],L[j][1],L[j][0]+L[j][1]*10**(-11)])
    X.sort(key = lambda x:x[2])
    lx = len(X)
    a,b = 0,0
    ans = 1
    for j in range(lx):
        na,nb = X[j][:2]
        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