2188. Minimum Time to Finish the Race Hard

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [2188] Minimum Time to Finish the Race
3 *
4 * You are given a 0-indexed 2D integer array tires where tires[i] = [fi, ri] indicates that the i^th tire can finish its x^th successive lap in fi * ri^(x-1) seconds.
5 * 
6 * 	For example, if fi = 3 and ri = 2, then the tire would finish its 1^st lap in 3 seconds, its 2^nd lap in 3 * 2 = 6 seconds, its 3^rd lap in 3 * 2^2 = 12 seconds, etc.
7 * 
8 * You are also given an integer changeTime and an integer numLaps.
9 * The race consists of numLaps laps and you may start the race with any tire. You have an unlimited supply of each tire and after every lap, you may change to any given tire (including the current tire type) if you wait changeTime seconds.
10 * Return the minimum time to finish the race.
11 *  
12 * Example 1:
13 * 
14 * Input: tires = [[2,3],[3,4]], changeTime = 5, numLaps = 4
15 * Output: 21
16 * Explanation: 
17 * Lap 1: Start with tire 0 and finish the lap in 2 seconds.
18 * Lap 2: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.
19 * Lap 3: Change tires to a new tire 0 for 5 seconds and then finish the lap in another 2 seconds.
20 * Lap 4: Continue with tire 0 and finish the lap in 2 * 3 = 6 seconds.
21 * Total time = 2 + 6 + 5 + 2 + 6 = 21 seconds.
22 * The minimum time to complete the race is 21 seconds.
23 * 
24 * Example 2:
25 * 
26 * Input: tires = [[1,10],[2,2],[3,4]], changeTime = 6, numLaps = 5
27 * Output: 25
28 * Explanation: 
29 * Lap 1: Start with tire 1 and finish the lap in 2 seconds.
30 * Lap 2: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.
31 * Lap 3: Change tires to a new tire 1 for 6 seconds and then finish the lap in another 2 seconds.
32 * Lap 4: Continue with tire 1 and finish the lap in 2 * 2 = 4 seconds.
33 * Lap 5: Change tires to tire 0 for 6 seconds then finish the lap in another 1 second.
34 * Total time = 2 + 4 + 6 + 2 + 4 + 6 + 1 = 25 seconds.
35 * The minimum time to complete the race is 25 seconds. 
36 * 
37 *  
38 * Constraints:
39 * 
40 * 	1 <= tires.length <= 10^5
41 * 	tires[i].length == 2
42 * 	1 <= fi, changeTime <= 10^5
43 * 	2 <= ri <= 10^5
44 * 	1 <= numLaps <= 1000
45 * 
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/minimum-time-to-finish-the-race/
50// discuss: https://leetcode.com/problems/minimum-time-to-finish-the-race/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55    pub fn minimum_finish_time(tires: Vec<Vec<i32>>, change_time: i32, num_laps: i32) -> i32 {
56        0
57    }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_2188() {
68    }
69}
70


Back
© 2025 bowen.ge All Rights Reserved.