Skip to content

feat: add weely contest 444 #4333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions solution/0300-0399/0368.Largest Divisible Subset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ impl Solution {
pub fn largest_divisible_subset(nums: Vec<i32>) -> Vec<i32> {
let mut nums = nums;
nums.sort();

let n = nums.len();
let mut f = vec![1; n];
let mut k = 0;

for i in 0..n {
for j in 0..i {
if nums[i] % nums[j] == 0 {
Expand All @@ -257,18 +257,18 @@ impl Solution {
k = i;
}
}

let mut m = f[k];
let mut ans = Vec::new();

for i in (0..=k).rev() {
if nums[k] % nums[i] == 0 && f[i] == m {
ans.push(nums[i]);
k = i;
m -= 1;
}
}

ans
}
}
Expand Down
10 changes: 5 additions & 5 deletions solution/0300-0399/0368.Largest Divisible Subset/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ impl Solution {
pub fn largest_divisible_subset(nums: Vec<i32>) -> Vec<i32> {
let mut nums = nums;
nums.sort();

let n = nums.len();
let mut f = vec![1; n];
let mut k = 0;

for i in 0..n {
for j in 0..i {
if nums[i] % nums[j] == 0 {
Expand All @@ -245,18 +245,18 @@ impl Solution {
k = i;
}
}

let mut m = f[k];
let mut ans = Vec::new();

for i in (0..=k).rev() {
if nums[k] % nums[i] == 0 && f[i] == m {
ans.push(nums[i]);
k = i;
m -= 1;
}
}

ans
}
}
Expand Down
12 changes: 6 additions & 6 deletions solution/0300-0399/0368.Largest Divisible Subset/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ impl Solution {
pub fn largest_divisible_subset(nums: Vec<i32>) -> Vec<i32> {
let mut nums = nums;
nums.sort();

let n = nums.len();
let mut f = vec![1; n];
let mut k = 0;

for i in 0..n {
for j in 0..i {
if nums[i] % nums[j] == 0 {
Expand All @@ -17,18 +17,18 @@ impl Solution {
k = i;
}
}

let mut m = f[k];
let mut ans = Vec::new();

for i in (0..=k).rev() {
if nums[k] % nums[i] == 0 && f[i] == m {
ans.push(nums[i]);
k = i;
m -= 1;
}
}

ans
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ function largestDivisibleSubset(nums: number[]): number[] {
}

return ans;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README.md
---

<!-- problem:start -->

# [3506. Find Time Required to Eliminate Bacterial Strains II 🔒](https://leetcode.cn/problems/find-time-required-to-eliminate-bacterial-strains-ii)

[English Version](/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README_EN.md)

## 题目描述

<!-- description:start -->

<p>You are given an integer array <code>timeReq</code> and an integer <code>splitTime</code>.</p>

<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>

<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>

<p>The WBC devises a clever strategy to fight the bacteria:</p>

<ul>
<li>The <code>i<sup>th</sup></code> bacterial strain takes <code>timeReq[i]</code> units of time to be eliminated.</li>
<li>A single WBC can eliminate <strong>only one</strong> bacterial strain. Afterwards, the WBC is exhausted and cannot perform any other tasks.</li>
<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>
<li><em>Only one</em> WBC can work on a single bacterial strain. Multiple WBCs <strong>cannot</strong> attack one strain in parallel.</li>
</ul>

<p>You must determine the <strong>minimum</strong> time required to eliminate all the bacterial strains.</p>

<p><strong>Note</strong> that the bacterial strains can be eliminated in any order.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4,5], splitTime = 2</span></p>

<p><strong>Output:</strong> <span class="example-io">12</span></p>

<p><strong>Explanation:</strong></p>

<p>The elimination process goes as follows:</p>

<ul>
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 2 units of time.</li>
<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>
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 2 + 2 + 4</code> and <code>t = 2 + 2 + 5</code>.</li>
</ul>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4], splitTime = 5</span></p>

<p><strong>Output:</strong>15</p>

<p><strong>Explanation:</strong></p>

<p>The elimination process goes as follows:</p>

<ul>
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 5 units of time.</li>
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 5 + 10</code> and <code>t = 5 + 4</code>.</li>
</ul>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>2 &lt;= timeReq.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= timeReq[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= splitTime &lt;= 10<sup>9</sup></code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README_EN.md
---

<!-- problem:start -->

# [3506. Find Time Required to Eliminate Bacterial Strains II 🔒](https://leetcode.com/problems/find-time-required-to-eliminate-bacterial-strains-ii)

[中文文档](/solution/3500-3599/3506.Find%20Time%20Required%20to%20Eliminate%20Bacterial%20Strains%20II/README.md)

## Description

<!-- description:start -->

<p>You are given an integer array <code>timeReq</code> and an integer <code>splitTime</code>.</p>

<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>

<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>

<p>The WBC devises a clever strategy to fight the bacteria:</p>

<ul>
<li>The <code>i<sup>th</sup></code> bacterial strain takes <code>timeReq[i]</code> units of time to be eliminated.</li>
<li>A single WBC can eliminate <strong>only one</strong> bacterial strain. Afterwards, the WBC is exhausted and cannot perform any other tasks.</li>
<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>
<li><em>Only one</em> WBC can work on a single bacterial strain. Multiple WBCs <strong>cannot</strong> attack one strain in parallel.</li>
</ul>

<p>You must determine the <strong>minimum</strong> time required to eliminate all the bacterial strains.</p>

<p><strong>Note</strong> that the bacterial strains can be eliminated in any order.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4,5], splitTime = 2</span></p>

<p><strong>Output:</strong> <span class="example-io">12</span></p>

<p><strong>Explanation:</strong></p>

<p>The elimination process goes as follows:</p>

<ul>
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 2 units of time.</li>
<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>
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 2 + 2 + 4</code> and <code>t = 2 + 2 + 5</code>.</li>
</ul>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">timeReq = [10,4], splitTime = 5</span></p>

<p><strong>Output:</strong>15</p>

<p><strong>Explanation:</strong></p>

<p>The elimination process goes as follows:</p>

<ul>
<li>Initially, there is a single WBC. The WBC splits into 2 WBCs after 5 units of time.</li>
<li>The 2 new WBCs eliminate the bacteria at times <code>t = 5 + 10</code> and <code>t = 5 + 4</code>.</li>
</ul>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>2 &lt;= timeReq.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= timeReq[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= splitTime &lt;= 10<sup>9</sup></code></li>
</ul>

<!-- description:end -->

## Solutions

<!-- solution:start -->

### Solution 1

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading
Loading