結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー 👑 rin204rin204
提出日時 2022-04-15 17:19:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,350 ms / 3,000 ms
コード長 847 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 206,396 KB
最終ジャッジ日時 2023-08-26 06:18:23
合計ジャッジ時間 22,081 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,064 KB
testcase_01 AC 76 ms
71,244 KB
testcase_02 AC 77 ms
71,280 KB
testcase_03 AC 92 ms
76,684 KB
testcase_04 AC 76 ms
71,240 KB
testcase_05 AC 78 ms
71,384 KB
testcase_06 AC 79 ms
71,456 KB
testcase_07 AC 79 ms
71,300 KB
testcase_08 AC 80 ms
76,284 KB
testcase_09 AC 88 ms
76,272 KB
testcase_10 AC 83 ms
76,564 KB
testcase_11 AC 83 ms
76,260 KB
testcase_12 AC 83 ms
75,968 KB
testcase_13 AC 85 ms
76,084 KB
testcase_14 AC 1,252 ms
200,032 KB
testcase_15 AC 1,304 ms
206,256 KB
testcase_16 AC 1,350 ms
206,080 KB
testcase_17 AC 1,306 ms
206,232 KB
testcase_18 AC 1,339 ms
206,232 KB
testcase_19 AC 1,300 ms
206,396 KB
testcase_20 AC 1,303 ms
206,184 KB
testcase_21 AC 1,191 ms
183,152 KB
testcase_22 AC 1,324 ms
203,928 KB
testcase_23 AC 1,322 ms
203,864 KB
testcase_24 AC 1,322 ms
203,952 KB
testcase_25 AC 1,268 ms
202,820 KB
testcase_26 AC 93 ms
76,556 KB
testcase_27 AC 964 ms
160,380 KB
testcase_28 AC 470 ms
114,128 KB
testcase_29 AC 476 ms
114,260 KB
testcase_30 AC 647 ms
135,924 KB
testcase_31 AC 954 ms
160,364 KB
権限があれば一括ダウンロードができます

ソースコード

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 = [[0] * K 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 in range(K):
                v = dp[bit ^ (1 << i)][k]
                dp[bit][(x + k) % K] += v

ans = dp[-1][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