結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー rin204rin204
提出日時 2022-04-15 17:19:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,263 ms / 3,000 ms
コード長 847 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 205,312 KB
最終ジャッジ日時 2024-06-07 01:34:40
合計ジャッジ時間 19,565 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,968 KB
testcase_01 AC 35 ms
52,352 KB
testcase_02 AC 37 ms
52,608 KB
testcase_03 AC 52 ms
63,104 KB
testcase_04 AC 38 ms
52,224 KB
testcase_05 AC 38 ms
52,608 KB
testcase_06 AC 38 ms
51,992 KB
testcase_07 AC 37 ms
52,992 KB
testcase_08 AC 45 ms
59,648 KB
testcase_09 AC 51 ms
61,824 KB
testcase_10 AC 44 ms
60,032 KB
testcase_11 AC 46 ms
60,416 KB
testcase_12 AC 45 ms
58,880 KB
testcase_13 AC 47 ms
60,416 KB
testcase_14 AC 1,186 ms
199,296 KB
testcase_15 AC 1,224 ms
205,044 KB
testcase_16 AC 1,263 ms
205,312 KB
testcase_17 AC 1,222 ms
205,056 KB
testcase_18 AC 1,220 ms
205,184 KB
testcase_19 AC 1,213 ms
205,184 KB
testcase_20 AC 1,208 ms
204,952 KB
testcase_21 AC 1,108 ms
183,676 KB
testcase_22 AC 1,221 ms
202,544 KB
testcase_23 AC 1,219 ms
203,008 KB
testcase_24 AC 1,239 ms
202,740 KB
testcase_25 AC 1,169 ms
201,460 KB
testcase_26 AC 55 ms
63,872 KB
testcase_27 AC 888 ms
160,556 KB
testcase_28 AC 418 ms
114,528 KB
testcase_29 AC 428 ms
114,692 KB
testcase_30 AC 603 ms
135,048 KB
testcase_31 AC 890 ms
160,444 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