結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー yuruhiyayuruhiya
提出日時 2021-08-07 14:20:44
言語 Crystal
(1.11.2)
結果
AC  
実行時間 1,513 ms / 3,000 ms
コード長 385 bytes
コンパイル時間 12,425 ms
コンパイル使用メモリ 293,460 KB
実行使用メモリ 140,456 KB
最終ジャッジ日時 2023-10-18 22:08:59
合計ジャッジ時間 35,782 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,324 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 6 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1,441 ms
140,456 KB
testcase_15 AC 1,505 ms
140,456 KB
testcase_16 AC 1,500 ms
140,456 KB
testcase_17 AC 1,513 ms
140,456 KB
testcase_18 AC 1,511 ms
140,456 KB
testcase_19 AC 1,508 ms
140,456 KB
testcase_20 AC 1,512 ms
140,456 KB
testcase_21 AC 1,341 ms
140,456 KB
testcase_22 AC 1,497 ms
140,456 KB
testcase_23 AC 1,487 ms
140,456 KB
testcase_24 AC 1,484 ms
140,456 KB
testcase_25 AC 1,468 ms
140,456 KB
testcase_26 AC 7 ms
4,348 KB
testcase_27 AC 1,118 ms
140,456 KB
testcase_28 AC 495 ms
75,896 KB
testcase_29 AC 497 ms
75,896 KB
testcase_30 AC 695 ms
75,896 KB
testcase_31 AC 1,109 ms
140,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = read_line.split.map(&.to_i)
c = read_line.split.map(&.to_i)
digits = (1..9).flat_map { |x| [x] * c[x - 1] }

dp = Array.new(2**n) { [0i64] * k }
dp[0][0] = 1
(0...2**n).each { |set| (0...k).each { |r| (0...n).each { |i|
  dp[set | (1 << i)][(r * 10 + digits[i]) % k] += dp[set][r] if set.bit(i) == 0
} } }

ans = dp.last[0]
c.each { |c| (1..c).each { |x| ans //= x } }
puts ans
0