結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー tobusakanatobusakana
提出日時 2022-10-23 17:25:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,353 ms / 3,000 ms
コード長 884 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 206,344 KB
最終ジャッジ日時 2023-09-15 03:14:12
合計ジャッジ時間 27,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,216 KB
testcase_01 AC 78 ms
71,320 KB
testcase_02 AC 75 ms
71,216 KB
testcase_03 AC 89 ms
76,612 KB
testcase_04 AC 74 ms
71,080 KB
testcase_05 AC 75 ms
71,112 KB
testcase_06 AC 76 ms
71,336 KB
testcase_07 AC 78 ms
75,672 KB
testcase_08 AC 77 ms
75,672 KB
testcase_09 AC 85 ms
76,668 KB
testcase_10 AC 84 ms
76,624 KB
testcase_11 AC 84 ms
76,420 KB
testcase_12 AC 83 ms
76,504 KB
testcase_13 AC 85 ms
76,552 KB
testcase_14 AC 1,529 ms
200,308 KB
testcase_15 AC 2,330 ms
206,220 KB
testcase_16 AC 2,333 ms
206,224 KB
testcase_17 AC 2,353 ms
206,264 KB
testcase_18 AC 2,323 ms
206,188 KB
testcase_19 AC 2,318 ms
206,280 KB
testcase_20 AC 455 ms
206,344 KB
testcase_21 AC 545 ms
190,688 KB
testcase_22 AC 633 ms
203,992 KB
testcase_23 AC 1,269 ms
203,704 KB
testcase_24 AC 963 ms
204,184 KB
testcase_25 AC 860 ms
202,780 KB
testcase_26 AC 93 ms
76,544 KB
testcase_27 AC 1,671 ms
170,524 KB
testcase_28 AC 855 ms
117,096 KB
testcase_29 AC 779 ms
117,468 KB
testcase_30 AC 1,144 ms
136,216 KB
testcase_31 AC 1,665 ms
169,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 14個の数のどれを使ったかの状態でDP
# ただし、重複ぶんを最後に割る

# dp[S][k] = 状態Sで、Kで割った余りがkである場合の数

import sys
readline = sys.stdin.readline
N,K = map(int,readline().split())
C = list(map(int,readline().split()))
X = []
for i in range(9):
  X += [(i + 1)] * (C[i])

dp = [[0] * K for i in range(1 << N)]

dp[0][0] = 1
for status in range(1 << N):
  for k in range(K): # スタートする状態
    if dp[status][k] == 0:
      continue
    for target in range(N): # 次に選ぶ数
      if (status >> target) & 1:
        continue
      next_status = status | (1 << target)
      next_k = (k * 10 + X[target]) % K
      dp[next_status][next_k] += dp[status][k]

perm = [1] * 15
for i in range(1, 15):
  perm[i] = perm[i - 1] * i
  
div = 1
for c in C:
  if c > 1:
    div *= perm[c]
    
print(dp[-1][0] // div)
0