結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー rin204rin204
提出日時 2022-04-15 17:17:45
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 854 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 456,448 KB
最終ジャッジ日時 2024-06-07 01:34:00
合計ジャッジ時間 8,429 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
57,344 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 RE -
testcase_03 AC 62 ms
66,432 KB
testcase_04 AC 39 ms
52,480 KB
testcase_05 RE -
testcase_06 AC 39 ms
51,712 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 50 ms
61,696 KB
testcase_10 AC 48 ms
60,416 KB
testcase_11 RE -
testcase_12 AC 45 ms
59,008 KB
testcase_13 AC 47 ms
61,056 KB
testcase_14 RE -
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)
fact = [1]
for i in range(1, n + 1):
    fact.append(fact[-1] * i)

for c in C:
    ans //= fact[c]
print(ans)
0