3594. Minimum Time to Transport All Individuals Hard
#Array#Dynamic Programming#Bit Manipulation#Graph Theory#Heap (Priority Queue)#Shortest Path#Bitmask
1/**
2 * [3594] Minimum Time to Transport All Individuals
3 *
4 * You are given n individuals at a base camp who need to cross a river to reach a destination using a single boat. The boat can carry at most k people at a time. The trip is affected by environmental conditions that vary cyclically over m stages.
5 * Each stage j has a speed multiplier mul[j]:
6 *
7 * If mul[j] > 1, the trip slows down.
8 * If mul[j] < 1, the trip speeds up.
9 *
10 * Each individual i has a rowing strength represented by time[i], the time (in minutes) it takes them to cross alone in neutral conditions.
11 * Rules:
12 *
13 * A group g departing at stage j takes time equal to the maximum time[i] among its members, multiplied by mul[j] minutes to reach the destination.
14 * After the group crosses the river in time d, the stage advances by floor(d) % m steps.
15 * If individuals are left behind, one person must return with the boat. Let r be the index of the returning person, the return takes time[r] × mul[current_stage], defined as return_time, and the stage advances by floor(return_time) % m.
16 *
17 * Return the minimum total time required to transport all individuals. If it is not possible to transport all individuals to the destination, return -1.
18 *
19 * <strong class="example">Example 1:
20 * <div class="example-block">
21 * Input: <span class="example-io">n = 1, k = 1, m = 2, time = [5], mul = [1.0,1.3]</span>
22 * Output: <span class="example-io">5.00000</span>
23 * Explanation:
24 *
25 * Individual 0 departs from stage 0, so crossing time = 5 × 1.00 = 5.00 minutes.
26 * All team members are now at the destination. Thus, the total time taken is 5.00 minutes.
27 * </div>
28 * <strong class="example">Example 2:
29 * <div class="example-block">
30 * Input: <span class="example-io">n = 3, k = 2, m = 3, time = [2,5,8], mul = [1.0,1.5,0.75]</span>
31 * Output: <span class="example-io">14.50000</span>
32 * Explanation:
33 * The optimal strategy is:
34 *
35 * Send individuals 0 and 2 from the base camp to the destination from stage 0. The crossing time is max(2, 8) × mul[0] = 8 × 1.00 = 8.00 minutes. The stage advances by floor(8.00) % 3 = 2, so the next stage is (0 + 2) % 3 = 2.
36 * Individual 0 returns alone from the destination to the base camp from stage 2. The return time is 2 × mul[2] = 2 × 0.75 = 1.50 minutes. The stage advances by floor(1.50) % 3 = 1, so the next stage is (2 + 1) % 3 = 0.
37 * Send individuals 0 and 1 from the base camp to the destination from stage 0. The crossing time is max(2, 5) × mul[0] = 5 × 1.00 = 5.00 minutes. The stage advances by floor(5.00) % 3 = 2, so the final stage is (0 + 2) % 3 = 2.
38 * All team members are now at the destination. The total time taken is 8.00 + 1.50 + 5.00 = 14.50 minutes.
39 * </div>
40 * <strong class="example">Example 3:
41 * <div class="example-block">
42 * Input: <span class="example-io">n = 2, k = 1, m = 2, time = [10,10], mul = [2.0,2.0]</span>
43 * Output: <span class="example-io">-1.00000</span>
44 * Explanation:
45 *
46 * Since the boat can only carry one person at a time, it is impossible to transport both individuals as one must always return. Thus, the answer is -1.00.
47 * </div>
48 *
49 * Constraints:
50 *
51 * 1 <= n == time.length <= 12
52 * 1 <= k <= 5
53 * 1 <= m <= 5
54 * 1 <= time[i] <= 100
55 * m == mul.length
56 * 0.5 <= mul[i] <= 2.0
57 *
58 */
59pub struct Solution {}
60
61// problem: https://leetcode.com/problems/minimum-time-to-transport-all-individuals/
62// discuss: https://leetcode.com/problems/minimum-time-to-transport-all-individuals/discuss/?currentPage=1&orderBy=most_votes&query=
63
64// submission codes start here
65
66impl Solution {
67 pub fn min_time(n: i32, k: i32, m: i32, time: Vec<i32>, mul: Vec<f64>) -> f64 {
68 0f64
69 }
70}
71
72// submission codes end
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77
78 #[test]
79 fn test_3594() {
80 }
81}
82Back
© 2026 bowen.ge All Rights Reserved.