結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー lloyzlloyz
提出日時 2021-12-27 23:26:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 940 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 212,668 KB
最終ジャッジ日時 2024-04-08 18:31:30
合計ジャッジ時間 8,595 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
60,948 KB
testcase_01 AC 43 ms
60,820 KB
testcase_02 AC 44 ms
60,820 KB
testcase_03 AC 58 ms
67,836 KB
testcase_04 AC 43 ms
60,820 KB
testcase_05 AC 43 ms
60,820 KB
testcase_06 AC 43 ms
60,820 KB
testcase_07 AC 44 ms
60,820 KB
testcase_08 AC 45 ms
60,820 KB
testcase_09 AC 55 ms
65,752 KB
testcase_10 AC 53 ms
65,772 KB
testcase_11 AC 55 ms
65,768 KB
testcase_12 AC 52 ms
63,680 KB
testcase_13 AC 54 ms
65,764 KB
testcase_14 AC 2,931 ms
200,232 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 #

def main():
    n, k = map(int, input().split())
    C = list(map(int, input().split()))
    L = []
    for i in range(9):
        for num in range(C[i]):
            L.append(i + 1)

    popcount = [0 for _ in range(200000)]
    for i in range(1, 200000):
        popcount[i] = popcount[i // 2] + i % 2

    fact = [1]
    for i in range(1, n + 1):
        fact.append(fact[-1] * i)

    DP = [[0] * k for _ in range(1 << n)]
    DP[0][0] = 1
    for bit in range(1 << n):
        digit = popcount[bit]
        for i in range(k):
            if DP[bit][i] != 0:
                for j in range(n):
                    if (bit >> j) & 1:
                        continue
                    num = pow(10, digit) * L[j] % k
                    r = (i + num) % k
                    DP[bit | (1 << j)][r] += DP[bit][i]
    ans = DP[-1][0]
    for i in range(9):
        ans //= fact[C[i]]
    print(ans)

if __name__ == '__main__':
    main()
0