結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-07-30 22:09:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,491 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 86,684 KB
実行使用メモリ 493,488 KB
最終ジャッジ日時 2023-10-14 05:02:48
合計ジャッジ時間 6,683 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,540 KB
testcase_01 AC 72 ms
71,524 KB
testcase_02 AC 73 ms
71,552 KB
testcase_03 AC 95 ms
76,784 KB
testcase_04 AC 70 ms
71,208 KB
testcase_05 AC 71 ms
71,144 KB
testcase_06 AC 72 ms
71,536 KB
testcase_07 AC 71 ms
71,540 KB
testcase_08 AC 71 ms
71,496 KB
testcase_09 AC 84 ms
76,372 KB
testcase_10 AC 85 ms
76,516 KB
testcase_11 AC 82 ms
76,460 KB
testcase_12 AC 78 ms
76,096 KB
testcase_13 AC 80 ms
76,208 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin
import math

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod

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

m2 = 92709568269121
fac,inv = modfac(100,m2)

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]
                dp[nexv][nexm] %= m2

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

for j in range(10):
    if c[j] >= 2:
        ans *= inv[c[j]]

print (ans % m2)
0