Skip to content

Commit efe5ed3

Browse files
committed
Runtime: 2419 ms (Top 5.20%) | Memory: 274.6 MB (Top 9.24%)
1 parent d7f11c5 commit efe5ed3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// Runtime: 2419 ms (Top 5.20%) | Memory: 274.6 MB (Top 9.24%)
12
class Solution {
23
public:
34
int minimumFinishTime(vector<vector<int>>& tires, int changeTime, int numLaps) {
45
int n = tires.size();
56
// to handle the cases where numLaps is small
6-
// without_change[i][j]: the total time to run j laps consecutively with tire i
7+
// without_change[i][j]: the total time to run j laps consecutively with tire i
78
vector<vector<int>> without_change(n, vector<int>(20, 2e9));
89
for (int i = 0; i < n; i++) {
910
without_change[i][1] = tires[i][0];
@@ -13,22 +14,22 @@ class Solution {
1314
without_change[i][j] = without_change[i][j-1] * tires[i][1];
1415
}
1516
// since we define it as the total time, rather than just the time for the j-th lap
16-
// we have to make it prefix sum
17+
// we have to make it prefix sum
1718
for (int j = 2; j < 20; j++) {
1819
if ((long long)without_change[i][j-1] + without_change[i][j] >= 2e9)
1920
break;
2021
without_change[i][j] += without_change[i][j-1];
2122
}
2223
}
23-
24-
// dp[x]: the minimum time to finish x laps
24+
25+
// dp[x]: the minimum time to finish x laps
2526
vector<int> dp(numLaps+1, 2e9);
2627
for (int i = 0; i < n; i++) {
2728
dp[1] = min(dp[1], tires[i][0]);
2829
}
2930
for (int x = 1; x <= numLaps; x++) {
3031
if (x < 20) {
31-
// x is small enough, so an optimal solution might never changes tires!
32+
// x is small enough, so an optimal solution might never changes tires!
3233
for (int i = 0; i < n; i++) {
3334
dp[x] = min(dp[x], without_change[i][x]);
3435
}
@@ -37,7 +38,7 @@ class Solution {
3738
dp[x] = min(dp[x], dp[j] + changeTime + dp[x-j]);
3839
}
3940
}
40-
41+
4142
return dp[numLaps];
4243
}
43-
};
44+
};

0 commit comments

Comments
 (0)