結果

問題 No.767 配られたジャパリまん
ユーザー chonbo0127chonbo0127
提出日時 2021-08-04 12:12:05
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,751 bytes
コンパイル時間 1,098 ms
コンパイル使用メモリ 87,396 KB
実行使用メモリ 261,180 KB
最終ジャッジ日時 2023-10-14 21:15:14
合計ジャッジ時間 8,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,468 KB
testcase_01 AC 75 ms
71,624 KB
testcase_02 AC 77 ms
71,288 KB
testcase_03 AC 78 ms
71,796 KB
testcase_04 AC 139 ms
78,020 KB
testcase_05 AC 354 ms
110,672 KB
testcase_06 AC 76 ms
71,408 KB
testcase_07 AC 78 ms
71,404 KB
testcase_08 AC 82 ms
76,508 KB
testcase_09 AC 134 ms
84,456 KB
testcase_10 AC 226 ms
94,284 KB
testcase_11 AC 171 ms
96,592 KB
testcase_12 AC 167 ms
89,752 KB
testcase_13 AC 216 ms
92,084 KB
testcase_14 AC 156 ms
98,936 KB
testcase_15 AC 114 ms
101,384 KB
testcase_16 AC 173 ms
93,972 KB
testcase_17 AC 92 ms
82,648 KB
testcase_18 AC 95 ms
84,072 KB
testcase_19 AC 170 ms
102,276 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

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][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]
        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