結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー aaaaaaaaaa2230
提出日時 2021-07-30 23:37:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,611 ms / 3,000 ms
コード長 623 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 205,312 KB
最終ジャッジ日時 2024-09-16 03:49:46
合計ジャッジ時間 18,682 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
C = list(map(int,input().split()))
l = []
for i,c in enumerate(C,1):
    for j in range(c):
        l.append(i)

ten = [1]
for i in range(n+1):
    ten.append(ten[-1]*10%k)

dp = [[0]*k for i in range(1<<n)]
dp[0][0] = 1
for i in range(1<<n):
    b = bin(i).count("1")
    for t in range(n):
        if i >> t & 1:
            continue
        for j in range(k):
            if dp[i][j] == 0:
                continue
            dp[i|1<<t][(j+ten[t]*l[b])%k] += dp[i][j]
ans = dp[-1][0]
fact = [1]
for i in range(1,n+1):
    fact.append(fact[-1]*i)
for c in C:
    ans //= fact[c]
print(ans)
0