結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
コンテスト
ユーザー 👑 SPD_9X2
提出日時 2021-07-30 22:04:39
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 860 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 148 ms
コンパイル使用メモリ 84,736 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2026-04-05 04:13:02
合計ジャッジ時間 8,016 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 11 MLE * 1 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""

"""

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