結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー 👑 SPD_9X2
提出日時 2021-07-30 22:04:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 860 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 82,076 KB
実行使用メモリ 488,448 KB
最終ジャッジ日時 2024-09-16 00:18:17
合計ジャッジ時間 5,685 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin
import math

N,K = map(int,stdin.readline().split())
mod = K

c = [0] + list(map(int,stdin.readline().split()))

C = []
for i in range(10):
    for j in range(c[i]):
        C.append(i)

dp = [ {} for i in range(2**N) ]
dic = dp
dp[0][0] = 1

for i in range(2**N):

    popcnt = 0
    for j in range(N):
        if 2**j & i > 0:
            popcnt += 1

    npow = pow(10,popcnt,mod)

    for j in range(N):

        if i & (2**j) == 0:
            
            nexv = i | (2**j)
            for nm in dic[i]:
                nexm = (nm + C[j] * npow) % mod

                if nexm not in dp[nexv]:
                    dp[nexv][nexm] = 0
                dp[nexv][nexm] += dp[i][nm]

if 0 not in dp[2**N-1]:
    ans = 0
else:
    ans = dp[2**N-1][0]

for j in range(10):
    ans //= math.factorial(c[j])

print (ans)
0