3533. Concatenated Divisibility Hard

@problem@discussion
#Array#Dynamic Programming#Bit Manipulation#Bitmask



1/**
2 * [3533] Concatenated Divisibility
3 *
4 * <p data-end="378" data-start="31">You are given an array of positive integers <code data-end="85" data-start="79">nums and a positive integer <code data-end="112" data-start="109">k.
5 * <p data-end="378" data-start="31">A <span data-keyword="permutation-array">permutation</span> of <code data-end="137" data-start="131">nums is said to form a <strong data-end="183" data-start="156">divisible concatenation if, when you concatenate the decimal representations of the numbers in the order specified by the permutation, the resulting number is divisible by <code data-end="359" data-start="356">k.
6 * <p data-end="561" data-start="380">Return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> permutation (when considered as a list of integers) that forms a divisible concatenation. If no such permutation exists, return an empty list.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [3,12,45], k = 5</span>
11 * Output: <span class="example-io">[3,12,45]</span>
12 * Explanation:
13 * <table data-end="896" data-start="441" node="[object Object]" style="border: 1px solid black;">
14 * 	<thead data-end="497" data-start="441">
15 * 		<tr data-end="497" data-start="441">
16 * 			<th data-end="458" data-start="441" style="border: 1px solid black;">Permutation</th>
17 * 			<th data-end="479" data-start="458" style="border: 1px solid black;">Concatenated Value</th>
18 * 			<th data-end="497" data-start="479" style="border: 1px solid black;">Divisible by 5</th>
19 * 		</tr>
20 * 	</thead>
21 * 	<tbody data-end="896" data-start="555">
22 * 		<tr data-end="611" data-start="555">
23 * 			<td style="border: 1px solid black;">[3, 12, 45]</td>
24 * 			<td style="border: 1px solid black;">31245</td>
25 * 			<td style="border: 1px solid black;">Yes</td>
26 * 		</tr>
27 * 		<tr data-end="668" data-start="612">
28 * 			<td style="border: 1px solid black;">[3, 45, 12]</td>
29 * 			<td style="border: 1px solid black;">34512</td>
30 * 			<td style="border: 1px solid black;">No</td>
31 * 		</tr>
32 * 		<tr data-end="725" data-start="669">
33 * 			<td style="border: 1px solid black;">[12, 3, 45]</td>
34 * 			<td style="border: 1px solid black;">12345</td>
35 * 			<td style="border: 1px solid black;">Yes</td>
36 * 		</tr>
37 * 		<tr data-end="782" data-start="726">
38 * 			<td style="border: 1px solid black;">[12, 45, 3]</td>
39 * 			<td style="border: 1px solid black;">12453</td>
40 * 			<td style="border: 1px solid black;">No</td>
41 * 		</tr>
42 * 		<tr data-end="839" data-start="783">
43 * 			<td style="border: 1px solid black;">[45, 3, 12]</td>
44 * 			<td style="border: 1px solid black;">45312</td>
45 * 			<td style="border: 1px solid black;">No</td>
46 * 		</tr>
47 * 		<tr data-end="896" data-start="840">
48 * 			<td style="border: 1px solid black;">[45, 12, 3]</td>
49 * 			<td style="border: 1px solid black;">45123</td>
50 * 			<td style="border: 1px solid black;">No</td>
51 * 		</tr>
52 * 	</tbody>
53 * </table>
54 * <p data-end="1618" data-start="1525">The lexicographically smallest permutation that forms a divisible concatenation is [3,12,45].
55 * </div>
56 * <strong class="example">Example 2:
57 * <div class="example-block">
58 * Input: <span class="example-io">nums = [10,5], k = 10</span>
59 * Output: <span class="example-io">[5,10]</span>
60 * Explanation:
61 * <table data-end="1421" data-start="1200" node="[object Object]" style="border: 1px solid black;">
62 * 	<thead data-end="1255" data-start="1200">
63 * 		<tr data-end="1255" data-start="1200">
64 * 			<th data-end="1216" data-start="1200" style="border: 1px solid black;">Permutation</th>
65 * 			<th data-end="1237" data-start="1216" style="border: 1px solid black;">Concatenated Value</th>
66 * 			<th data-end="1255" data-start="1237" style="border: 1px solid black;">Divisible by 10</th>
67 * 		</tr>
68 * 	</thead>
69 * 	<tbody data-end="1421" data-start="1312">
70 * 		<tr data-end="1366" data-start="1312">
71 * 			<td style="border: 1px solid black;">[5, 10]</td>
72 * 			<td style="border: 1px solid black;">510</td>
73 * 			<td style="border: 1px solid black;">Yes</td>
74 * 		</tr>
75 * 		<tr data-end="1421" data-start="1367">
76 * 			<td style="border: 1px solid black;">[10, 5]</td>
77 * 			<td style="border: 1px solid black;">105</td>
78 * 			<td style="border: 1px solid black;">No</td>
79 * 		</tr>
80 * 	</tbody>
81 * </table>
82 * <p data-end="2011" data-start="1921">The lexicographically smallest permutation that forms a divisible concatenation is [5,10].
83 * </div>
84 * <strong class="example">Example 3:
85 * <div class="example-block">
86 * Input: <span class="example-io">nums = [1,2,3], k = 5</span>
87 * Output: <span class="example-io">[]</span>
88 * Explanation:
89 * Since no permutation of <code data-end="177" data-start="171">nums forms a valid divisible concatenation, return an empty list.
90 * </div>
91 *  
92 * Constraints:
93 * 
94 * 	1 <= nums.length <= 13
95 * 	1 <= nums[i] <= 10^5
96 * 	1 <= k <= 100
97 * 
98 */
99pub struct Solution {}
100
101// problem: https://leetcode.com/problems/concatenated-divisibility/
102// discuss: https://leetcode.com/problems/concatenated-divisibility/discuss/?currentPage=1&orderBy=most_votes&query=
103
104// submission codes start here
105
106impl Solution {
107    pub fn concatenated_divisibility(nums: Vec<i32>, k: i32) -> Vec<i32> {
108        vec![]
109    }
110}
111
112// submission codes end
113
114#[cfg(test)]
115mod tests {
116    use super::*;
117
118    #[test]
119    fn test_3533() {
120    }
121}
122

Back
© 2026 bowen.ge All Rights Reserved.