結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー rlangevinrlangevin
提出日時 2023-04-04 00:39:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 986 ms / 3,000 ms
コード長 497 bytes
コンパイル時間 1,316 ms
コンパイル使用メモリ 81,560 KB
実行使用メモリ 203,104 KB
最終ジャッジ日時 2023-10-25 09:33:43
合計ジャッジ時間 15,648 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,396 KB
testcase_01 AC 40 ms
53,396 KB
testcase_02 AC 39 ms
53,396 KB
testcase_03 AC 62 ms
66,812 KB
testcase_04 AC 40 ms
53,396 KB
testcase_05 AC 43 ms
53,396 KB
testcase_06 AC 39 ms
53,396 KB
testcase_07 AC 42 ms
58,704 KB
testcase_08 AC 49 ms
61,848 KB
testcase_09 AC 55 ms
64,988 KB
testcase_10 AC 48 ms
61,836 KB
testcase_11 AC 54 ms
64,224 KB
testcase_12 AC 50 ms
62,004 KB
testcase_13 AC 49 ms
61,884 KB
testcase_14 AC 986 ms
194,088 KB
testcase_15 AC 973 ms
200,104 KB
testcase_16 AC 964 ms
200,092 KB
testcase_17 AC 974 ms
200,088 KB
testcase_18 AC 967 ms
200,256 KB
testcase_19 AC 983 ms
203,104 KB
testcase_20 AC 715 ms
201,412 KB
testcase_21 AC 728 ms
184,476 KB
testcase_22 AC 735 ms
198,112 KB
testcase_23 AC 800 ms
197,768 KB
testcase_24 AC 763 ms
197,788 KB
testcase_25 AC 765 ms
196,380 KB
testcase_26 AC 66 ms
68,368 KB
testcase_27 AC 694 ms
165,732 KB
testcase_28 AC 326 ms
110,748 KB
testcase_29 AC 308 ms
111,592 KB
testcase_30 AC 469 ms
132,980 KB
testcase_31 AC 655 ms
163,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n, k):
    return n * K + k

N, K = map(int, input().split())
C = list(map(int, input().split()))
D = []
for i in range(9):
    D.extend([i + 1] * C[i])
    
N2 = 1 << N
dp = [0] * (N2 * K)
dp[0] = 1
for s in range(N2):
    for j in range(N):
        if (s >> j) & 1:
            continue
        if j and (s >> (j - 1)) & 1 == 0 and (D[j - 1] == D[j]):
            continue
        for k in range(K):
            dp[f(s|(1<<j), (k*10 + D[j])%K)] += dp[f(s, k)]
print(dp[f(N2-1,0)])         
0