結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 53 ms
64,176 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 40 ms
57,044 KB
testcase_08 AC 41 ms
59,128 KB
testcase_09 AC 51 ms
64,164 KB
testcase_10 AC 49 ms
62,108 KB
testcase_11 AC 49 ms
62,104 KB
testcase_12 AC 47 ms
61,976 KB
testcase_13 AC 49 ms
62,108 KB
testcase_14 AC 2,177 ms
198,520 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 518 ms
204,536 KB
testcase_21 AC 624 ms
188,792 KB
testcase_22 AC 827 ms
202,232 KB
testcase_23 AC 1,740 ms
202,232 KB
testcase_24 AC 1,248 ms
202,104 KB
testcase_25 AC 1,090 ms
200,824 KB
testcase_26 AC 55 ms
66,348 KB
testcase_27 AC 2,465 ms
168,568 KB
testcase_28 AC 1,232 ms
115,064 KB
testcase_29 AC 1,104 ms
115,832 KB
testcase_30 AC 1,676 ms
134,392 KB
testcase_31 AC 2,464 ms
168,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    C = list(map(int, input().split()))
    L = []
    for i in range(9):
        L += [i + 1] * C[i]
    
    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):
        for i in range(k):
            if DP[bit][i] == 0:
                continue
            for j in range(n):
                if bit & (1 << j):
                    continue
                r = (10 * i + L[j]) % k
                nbit = bit | (1 << j)
                DP[nbit][r] += DP[bit][i]
    ans = DP[-1][0]
    for i in range(9):
        ans //= fact[C[i]]
    print(ans)

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