結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー tobusakanatobusakana
提出日時 2022-10-23 17:24:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,329 ms / 3,000 ms
コード長 884 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 84,552 KB
実行使用メモリ 206,360 KB
最終ジャッジ日時 2023-09-15 03:13:15
合計ジャッジ時間 28,803 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,108 KB
testcase_01 AC 83 ms
71,432 KB
testcase_02 AC 78 ms
71,244 KB
testcase_03 AC 103 ms
76,448 KB
testcase_04 AC 78 ms
71,196 KB
testcase_05 AC 78 ms
71,396 KB
testcase_06 AC 79 ms
71,248 KB
testcase_07 AC 81 ms
75,508 KB
testcase_08 AC 81 ms
75,452 KB
testcase_09 AC 89 ms
76,460 KB
testcase_10 AC 87 ms
76,424 KB
testcase_11 AC 89 ms
76,444 KB
testcase_12 AC 88 ms
76,448 KB
testcase_13 AC 90 ms
76,456 KB
testcase_14 AC 1,544 ms
200,120 KB
testcase_15 AC 2,329 ms
206,160 KB
testcase_16 AC 2,319 ms
206,148 KB
testcase_17 AC 2,313 ms
206,340 KB
testcase_18 AC 2,313 ms
206,352 KB
testcase_19 AC 2,313 ms
206,360 KB
testcase_20 AC 456 ms
206,100 KB
testcase_21 AC 544 ms
190,464 KB
testcase_22 AC 636 ms
203,900 KB
testcase_23 AC 1,273 ms
203,844 KB
testcase_24 AC 959 ms
204,100 KB
testcase_25 AC 849 ms
202,648 KB
testcase_26 AC 86 ms
76,732 KB
testcase_27 AC 1,675 ms
170,060 KB
testcase_28 AC 851 ms
116,556 KB
testcase_29 AC 788 ms
117,460 KB
testcase_30 AC 1,147 ms
136,092 KB
testcase_31 AC 1,677 ms
169,552 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] * 14
for i in range(1, 14):
  perm[i] = perm[i - 1] * i
  
div = 1
for c in C:
  if c > 1:
    div *= perm[c]
    
print(dp[-1][0] // div)
0