結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー 👑 rin204rin204
提出日時 2022-04-15 17:18:01
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 857 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 492,284 KB
最終ジャッジ日時 2023-08-26 06:17:49
合計ジャッジ時間 9,441 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
75,652 KB
testcase_01 AC 78 ms
71,232 KB
testcase_02 AC 76 ms
71,460 KB
testcase_03 AC 103 ms
76,828 KB
testcase_04 AC 77 ms
71,208 KB
testcase_05 AC 77 ms
71,160 KB
testcase_06 AC 79 ms
71,444 KB
testcase_07 AC 77 ms
71,324 KB
testcase_08 AC 76 ms
71,308 KB
testcase_09 AC 88 ms
76,528 KB
testcase_10 AC 86 ms
76,076 KB
testcase_11 AC 89 ms
76,796 KB
testcase_12 AC 81 ms
76,060 KB
testcase_13 AC 84 ms
76,112 KB
testcase_14 AC 2,438 ms
310,872 KB
testcase_15 TLE -
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 #

from math import gcd

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x0000003f

n, K = map(int, input().split())
C = list(map(int, input().split()))
lst = []
for i, c in enumerate(C, 1):
    lst += [i] * c

ten = [1]
for _ in range(n):
    ten.append(ten[-1] * 10 % K)

dp = [{} for _ in range(1 << n)]
dp[0][0] = 1

for bit in range(1, 1 << n):
    pc = popcount(bit)
    for i in range(n):
        if bit >> i & 1:
            x = lst[i] * ten[pc - 1] % K
            for k, v in dp[bit ^ (1 << i)].items():
                dp[bit][(x + k) % K] = dp[bit].get((x + k) % K, 0) + v

ans = dp[-1].get(0, 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