Skip to content

Commit 3bdf01e

Browse files
authored
feat: add weely contest 444 (#4333)
1 parent eef5794 commit 3bdf01e

File tree

19 files changed

+1312
-18
lines changed

19 files changed

+1312
-18
lines changed

Diff for: solution/0300-0399/0368.Largest Divisible Subset/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ impl Solution {
242242
pub fn largest_divisible_subset(nums: Vec<i32>) -> Vec<i32> {
243243
let mut nums = nums;
244244
nums.sort();
245-
245+
246246
let n = nums.len();
247247
let mut f = vec![1; n];
248248
let mut k = 0;
249-
249+
250250
for i in 0..n {
251251
for j in 0..i {
252252
if nums[i] % nums[j] == 0 {
@@ -257,18 +257,18 @@ impl Solution {
257257
k = i;
258258
}
259259
}
260-
260+
261261
let mut m = f[k];
262262
let mut ans = Vec::new();
263-
263+
264264
for i in (0..=k).rev() {
265265
if nums[k] % nums[i] == 0 && f[i] == m {
266266
ans.push(nums[i]);
267267
k = i;
268268
m -= 1;
269269
}
270270
}
271-
271+
272272
ans
273273
}
274274
}

Diff for: solution/0300-0399/0368.Largest Divisible Subset/README_EN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ impl Solution {
230230
pub fn largest_divisible_subset(nums: Vec<i32>) -> Vec<i32> {
231231
let mut nums = nums;
232232
nums.sort();
233-
233+
234234
let n = nums.len();
235235
let mut f = vec![1; n];
236236
let mut k = 0;
237-
237+
238238
for i in 0..n {
239239
for j in 0..i {
240240
if nums[i] % nums[j] == 0 {
@@ -245,18 +245,18 @@ impl Solution {
245245
k = i;
246246
}
247247
}
248-
248+
249249
let mut m = f[k];
250250
let mut ans = Vec::new();
251-
251+
252252
for i in (0..=k).rev() {
253253
if nums[k] % nums[i] == 0 && f[i] == m {
254254
ans.push(nums[i]);
255255
k = i;
256256
m -= 1;
257257
}
258258
}
259-
259+
260260
ans
261261
}
262262
}

Diff for: solution/0300-0399/0368.Largest Divisible Subset/Solution.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ impl Solution {
22
pub fn largest_divisible_subset(nums: Vec<i32>) -> Vec<i32> {
33
let mut nums = nums;
44
nums.sort();
5-
5+
66
let n = nums.len();
77
let mut f = vec![1; n];
88
let mut k = 0;
9-
9+
1010
for i in 0..n {
1111
for j in 0..i {
1212
if nums[i] % nums[j] == 0 {
@@ -17,18 +17,18 @@ impl Solution {
1717
k = i;
1818
}
1919
}
20-
20+
2121
let mut m = f[k];
2222
let mut ans = Vec::new();
23-
23+
2424
for i in (0..=k).rev() {
2525
if nums[k] % nums[i] == 0 && f[i] == m {
2626
ans.push(nums[i]);
2727
k = i;
2828
m -= 1;
2929
}
3030
}
31-
31+
3232
ans
3333
}
34-
}
34+
}

Diff for: solution/0300-0399/0368.Largest Divisible Subset/Solution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ function largestDivisibleSubset(nums: number[]): number[] {
2626
}
2727

2828
return ans;
29-
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
comments: true
3+
difficulty: 困难
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3506. Find Time Required to Eliminate Bacterial Strains II 🔒](https://leetcode.cn/problems/find-time-required-to-eliminate-bacterial-strains-ii)
10+
11+
[English Version](/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an integer array <code>timeReq</code> and an integer <code>splitTime</code>.</p>
18+
19+
<p>In the microscopic world of the human body, the immune system faces an extraordinary challenge: combatting a rapidly multiplying bacterial colony that threatens the body&#39;s survival.</p>
20+
21+
<p>Initially, only one <strong>white blood cell</strong> (<strong>WBC</strong>) is deployed to eliminate the bacteria. However, the lone WBC quickly realizes it cannot keep up with the bacterial growth rate.</p>
22+
23+
<p>The WBC devises a clever strategy to fight the bacteria:</p>
24+
25+
<ul>
26+
<li>The <code>i<sup>th</sup></code> bacterial strain takes <code>timeReq[i]</code> units of time to be eliminated.</li>
27+
<li>A single WBC can eliminate <strong>only one</strong> bacterial strain. Afterwards, the WBC is exhausted and cannot perform any other tasks.</li>
28+
<li>A WBC can split itself into two WBCs, but this requires <code>splitTime</code> units of time. Once split, the two WBCs can work in <strong>parallel</strong> on eliminating the bacteria.</li>
29+
<li><em>Only one</em> WBC can work on a single bacterial strain. Multiple WBCs <strong>cannot</strong> attack one strain in parallel.</li>
30+
</ul>
31+
32+
<p>You must determine the <strong>minimum</strong> time required to eliminate all the bacterial strains.</p>
33+
34+
<p><strong>Note</strong> that the bacterial strains can be eliminated in any order.</p>
35+
36+
<p>&nbsp;</p>
37+
<p><strong class="example">Example 1:</strong></p>
38+
39+
<div class="example-block">
40+
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4,5], splitTime = 2</span></p>
41+
42+
<p><strong>Output:</strong> <span class="example-io">12</span></p>
43+
44+
<p><strong>Explanation:</strong></p>
45+
46+
<p>The elimination process goes as follows:</p>
47+
48+
<ul>
49+
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 2 units of time.</li>
50+
<li>One of the WBCs eliminates strain 0 at a time <code>t = 2 + 10 = 12.</code> The other WBC splits again, using 2 units of time.</li>
51+
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 2 + 2 + 4</code> and <code>t = 2 + 2 + 5</code>.</li>
52+
</ul>
53+
</div>
54+
55+
<p><strong class="example">Example 2:</strong></p>
56+
57+
<div class="example-block">
58+
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4], splitTime = 5</span></p>
59+
60+
<p><strong>Output:</strong>15</p>
61+
62+
<p><strong>Explanation:</strong></p>
63+
64+
<p>The elimination process goes as follows:</p>
65+
66+
<ul>
67+
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 5 units of time.</li>
68+
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 5 + 10</code> and <code>t = 5 + 4</code>.</li>
69+
</ul>
70+
</div>
71+
72+
<p>&nbsp;</p>
73+
<p><strong>Constraints:</strong></p>
74+
75+
<ul>
76+
<li><code>2 &lt;= timeReq.length &lt;= 10<sup>5</sup></code></li>
77+
<li><code>1 &lt;= timeReq[i] &lt;= 10<sup>9</sup></code></li>
78+
<li><code>1 &lt;= splitTime &lt;= 10<sup>9</sup></code></li>
79+
</ul>
80+
81+
<!-- description:end -->
82+
83+
## 解法
84+
85+
<!-- solution:start -->
86+
87+
### 方法一
88+
89+
<!-- tabs:start -->
90+
91+
#### Python3
92+
93+
```python
94+
95+
```
96+
97+
#### Java
98+
99+
```java
100+
101+
```
102+
103+
#### C++
104+
105+
```cpp
106+
107+
```
108+
109+
#### Go
110+
111+
```go
112+
113+
```
114+
115+
<!-- tabs:end -->
116+
117+
<!-- solution:end -->
118+
119+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
comments: true
3+
difficulty: Hard
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3506. Find Time Required to Eliminate Bacterial Strains II 🔒](https://leetcode.com/problems/find-time-required-to-eliminate-bacterial-strains-ii)
10+
11+
[中文文档](/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an integer array <code>timeReq</code> and an integer <code>splitTime</code>.</p>
18+
19+
<p>In the microscopic world of the human body, the immune system faces an extraordinary challenge: combatting a rapidly multiplying bacterial colony that threatens the body&#39;s survival.</p>
20+
21+
<p>Initially, only one <strong>white blood cell</strong> (<strong>WBC</strong>) is deployed to eliminate the bacteria. However, the lone WBC quickly realizes it cannot keep up with the bacterial growth rate.</p>
22+
23+
<p>The WBC devises a clever strategy to fight the bacteria:</p>
24+
25+
<ul>
26+
<li>The <code>i<sup>th</sup></code> bacterial strain takes <code>timeReq[i]</code> units of time to be eliminated.</li>
27+
<li>A single WBC can eliminate <strong>only one</strong> bacterial strain. Afterwards, the WBC is exhausted and cannot perform any other tasks.</li>
28+
<li>A WBC can split itself into two WBCs, but this requires <code>splitTime</code> units of time. Once split, the two WBCs can work in <strong>parallel</strong> on eliminating the bacteria.</li>
29+
<li><em>Only one</em> WBC can work on a single bacterial strain. Multiple WBCs <strong>cannot</strong> attack one strain in parallel.</li>
30+
</ul>
31+
32+
<p>You must determine the <strong>minimum</strong> time required to eliminate all the bacterial strains.</p>
33+
34+
<p><strong>Note</strong> that the bacterial strains can be eliminated in any order.</p>
35+
36+
<p>&nbsp;</p>
37+
<p><strong class="example">Example 1:</strong></p>
38+
39+
<div class="example-block">
40+
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4,5], splitTime = 2</span></p>
41+
42+
<p><strong>Output:</strong> <span class="example-io">12</span></p>
43+
44+
<p><strong>Explanation:</strong></p>
45+
46+
<p>The elimination process goes as follows:</p>
47+
48+
<ul>
49+
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 2 units of time.</li>
50+
<li>One of the WBCs eliminates strain 0 at a time <code>t = 2 + 10 = 12.</code> The other WBC splits again, using 2 units of time.</li>
51+
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 2 + 2 + 4</code> and <code>t = 2 + 2 + 5</code>.</li>
52+
</ul>
53+
</div>
54+
55+
<p><strong class="example">Example 2:</strong></p>
56+
57+
<div class="example-block">
58+
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4], splitTime = 5</span></p>
59+
60+
<p><strong>Output:</strong>15</p>
61+
62+
<p><strong>Explanation:</strong></p>
63+
64+
<p>The elimination process goes as follows:</p>
65+
66+
<ul>
67+
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 5 units of time.</li>
68+
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 5 + 10</code> and <code>t = 5 + 4</code>.</li>
69+
</ul>
70+
</div>
71+
72+
<p>&nbsp;</p>
73+
<p><strong>Constraints:</strong></p>
74+
75+
<ul>
76+
<li><code>2 &lt;= timeReq.length &lt;= 10<sup>5</sup></code></li>
77+
<li><code>1 &lt;= timeReq[i] &lt;= 10<sup>9</sup></code></li>
78+
<li><code>1 &lt;= splitTime &lt;= 10<sup>9</sup></code></li>
79+
</ul>
80+
81+
<!-- description:end -->
82+
83+
## Solutions
84+
85+
<!-- solution:start -->
86+
87+
### Solution 1
88+
89+
<!-- tabs:start -->
90+
91+
#### Python3
92+
93+
```python
94+
95+
```
96+
97+
#### Java
98+
99+
```java
100+
101+
```
102+
103+
#### C++
104+
105+
```cpp
106+
107+
```
108+
109+
#### Go
110+
111+
```go
112+
113+
```
114+
115+
<!-- tabs:end -->
116+
117+
<!-- solution:end -->
118+
119+
<!-- problem:end -->

0 commit comments

Comments
 (0)