From bfecda9fc075301d18cfcd2906375522e7da26aa Mon Sep 17 00:00:00 2001 From: acbin <44314231+acbin@users.noreply.github.com> Date: Sun, 24 Dec 2023 08:44:22 +0000 Subject: [PATCH 1/2] feat: add weekly contest 377 --- .../README.md | 4 +- .../README_EN.md | 4 +- .../README.md | 4 +- .../README_EN.md | 4 +- .../README.md | 4 +- .../README_EN.md | 4 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../images/screenshot-2023-11-10-012513.png | Bin .../images/screenshot-2023-11-10-012614.png | Bin .../images/screenshot-2023-11-10-012641.png | Bin .../2974.Minimum Number Game/README.md | 88 +++++++++++++ .../2974.Minimum Number Game/README_EN.md | 78 ++++++++++++ .../README.md | 93 ++++++++++++++ .../README_EN.md | 83 +++++++++++++ .../images/maxsquareareaexample1.png | Bin 0 -> 5300 bytes .../screenshot-from-2023-11-05-22-40-25.png | Bin 0 -> 5058 bytes .../README.md | 108 ++++++++++++++++ .../README_EN.md | 92 ++++++++++++++ .../README.md | 117 ++++++++++++++++++ .../README_EN.md | 105 ++++++++++++++++ solution/CONTEST_README.md | 15 ++- solution/CONTEST_README_EN.md | 15 ++- solution/README.md | 22 ++-- solution/README_EN.md | 22 ++-- solution/main.py | 2 +- solution/summary.md | 10 +- solution/summary_en.md | 8 ++ 28 files changed, 852 insertions(+), 50 deletions(-) rename solution/{10000-10099/10031.Count the Number of Incremovable Subarrays I => 2900-2999/2970.Count the Number of Incremovable Subarrays I}/README.md (90%) rename solution/{10000-10099/10031.Count the Number of Incremovable Subarrays I => 2900-2999/2970.Count the Number of Incremovable Subarrays I}/README_EN.md (90%) rename solution/{10000-10099/10032.Find Polygon With the Largest Perimeter => 2900-2999/2971.Find Polygon With the Largest Perimeter}/README.md (92%) rename solution/{10000-10099/10032.Find Polygon With the Largest Perimeter => 2900-2999/2971.Find Polygon With the Largest Perimeter}/README_EN.md (92%) rename solution/{10000-10099/10033.Count the Number of Incremovable Subarrays II => 2900-2999/2972.Count the Number of Incremovable Subarrays II}/README.md (90%) rename solution/{10000-10099/10033.Count the Number of Incremovable Subarrays II => 2900-2999/2972.Count the Number of Incremovable Subarrays II}/README_EN.md (90%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/README.md (83%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/README_EN.md (81%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/images/screenshot-2023-11-10-012513.png (100%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/images/screenshot-2023-11-10-012614.png (100%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/images/screenshot-2023-11-10-012641.png (100%) create mode 100644 solution/2900-2999/2974.Minimum Number Game/README.md create mode 100644 solution/2900-2999/2974.Minimum Number Game/README_EN.md create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/maxsquareareaexample1.png create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/screenshot-from-2023-11-05-22-40-25.png create mode 100644 solution/2900-2999/2976.Minimum Cost to Convert String I/README.md create mode 100644 solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md create mode 100644 solution/2900-2999/2977.Minimum Cost to Convert String II/README.md create mode 100644 solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md diff --git a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README.md b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md similarity index 90% rename from solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README.md rename to solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md index 5052a2c5474b8..f5d679e62ba7c 100644 --- a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README.md +++ b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md @@ -1,6 +1,6 @@ -# [10031. 统计移除递增子数组的数目 I](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-i) +# [2970. 统计移除递增子数组的数目 I](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-i) -[English Version](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) +[English Version](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) ## 题目描述 diff --git a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README_EN.md b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md similarity index 90% rename from solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README_EN.md rename to solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md index 73c51d2512bf1..ee448266153f3 100644 --- a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README_EN.md +++ b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md @@ -1,6 +1,6 @@ -# [10031. Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) +# [2970. Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) -[中文文档](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) +[中文文档](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) ## Description diff --git a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README.md b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md similarity index 92% rename from solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README.md rename to solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md index 82134d9808f7f..10b0c7313d2b3 100644 --- a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README.md +++ b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md @@ -1,6 +1,6 @@ -# [10032. 找到最大周长的多边形](https://leetcode.cn/problems/find-polygon-with-the-largest-perimeter) +# [2971. 找到最大周长的多边形](https://leetcode.cn/problems/find-polygon-with-the-largest-perimeter) -[English Version](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) +[English Version](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) ## 题目描述 diff --git a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README_EN.md b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md similarity index 92% rename from solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README_EN.md rename to solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md index b6ed1d3532517..c5cf4e2076e08 100644 --- a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README_EN.md +++ b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md @@ -1,6 +1,6 @@ -# [10032. Find Polygon With the Largest Perimeter](https://leetcode.com/problems/find-polygon-with-the-largest-perimeter) +# [2971. Find Polygon With the Largest Perimeter](https://leetcode.com/problems/find-polygon-with-the-largest-perimeter) -[中文文档](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) +[中文文档](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) ## Description diff --git a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README.md b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md similarity index 90% rename from solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README.md rename to solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md index 8e3d272377d9d..5ad5420d994a3 100644 --- a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README.md +++ b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md @@ -1,6 +1,6 @@ -# [10033. 统计移除递增子数组的数目 II](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-ii) +# [2972. 统计移除递增子数组的数目 II](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-ii) -[English Version](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) +[English Version](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) ## 题目描述 diff --git a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README_EN.md b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md similarity index 90% rename from solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README_EN.md rename to solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md index 26403a6c7035b..8e94f2be7fce9 100644 --- a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README_EN.md +++ b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md @@ -1,6 +1,6 @@ -# [10033. Count the Number of Incremovable Subarrays II](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-ii) +# [2972. Count the Number of Incremovable Subarrays II](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-ii) -[中文文档](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) +[中文文档](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) ## Description diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README.md b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md similarity index 83% rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README.md rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md index be16654bda485..88f9b1a6d6f99 100644 --- a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README.md +++ b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md @@ -1,6 +1,6 @@ -# [10034. 树中每个节点放置的金币数目](https://leetcode.cn/problems/find-number-of-coins-to-place-in-tree-nodes) +# [2973. 树中每个节点放置的金币数目](https://leetcode.cn/problems/find-number-of-coins-to-place-in-tree-nodes) -[English Version](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) +[English Version](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) ## 题目描述 @@ -23,7 +23,7 @@

示例 1:

-

+

 输入:edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]
@@ -33,7 +33,7 @@
 
 

示例 2:

-

+

 输入:edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]
@@ -47,7 +47,7 @@
 
 

示例 3:

-

+

 输入:edges = [[0,1],[0,2]], cost = [1,2,-2]
diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README_EN.md b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md
similarity index 81%
rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README_EN.md
rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md
index 39a5e9eeb1ff3..999fed7da5917 100644
--- a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README_EN.md	
+++ b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md	
@@ -1,6 +1,6 @@
-# [10034. Find Number of Coins to Place in Tree Nodes](https://leetcode.com/problems/find-number-of-coins-to-place-in-tree-nodes)
+# [2973. Find Number of Coins to Place in Tree Nodes](https://leetcode.com/problems/find-number-of-coins-to-place-in-tree-nodes)
 
-[中文文档](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md)
+[中文文档](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md)
 
 ## Description
 
@@ -19,7 +19,7 @@
 
 

 

Example 1:

- +
 Input: edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]
 Output: [120,1,1,1,1,1]
@@ -27,7 +27,7 @@
 

Example 2:

- +
 Input: edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]
 Output: [280,140,32,1,1,1,1,1,1]
@@ -39,7 +39,7 @@
 

Example 3:

- +
 Input: edges = [[0,1],[0,2]], cost = [1,2,-2]
 Output: [0,1,1]
diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png
similarity index 100%
rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png
rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png
diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png
similarity index 100%
rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png
rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png
diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png
similarity index 100%
rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png
rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png
diff --git a/solution/2900-2999/2974.Minimum Number Game/README.md b/solution/2900-2999/2974.Minimum Number Game/README.md
new file mode 100644
index 0000000000000..7d8f07198dfa5
--- /dev/null
+++ b/solution/2900-2999/2974.Minimum Number Game/README.md	
@@ -0,0 +1,88 @@
+# [2974. 最小数字游戏](https://leetcode.cn/problems/minimum-number-game)
+
+[English Version](/solution/2900-2999/2974.Minimum%20Number%20Game/README_EN.md)
+
+## 题目描述
+
+
+
+

你有一个下标从 0 开始、长度为 偶数 的整数数组 nums ,同时还有一个空数组 arr 。Alice 和 Bob 决定玩一个游戏,游戏中每一轮 Alice 和 Bob 都会各自执行一次操作。游戏规则如下:

+ +
    +
  • 每一轮,Alice 先从 nums 中移除一个 最小 元素,然后 Bob 执行同样的操作。
  • +
  • 接着,Bob 会将移除的元素添加到数组 arr 中,然后 Alice 也执行同样的操作。
  • +
  • 游戏持续进行,直到 nums 变为空。
  • +
+ +

返回结果数组 arr

+ +

 

+ +

示例 1:

+ +
+输入:nums = [5,4,2,3]
+输出:[3,2,5,4]
+解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 3 。然后 Bob 先将 3 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [3,2] 。
+第二轮开始时,nums = [5,4] 。Alice 先移除 4 ,然后 Bob 移除 5 。接着他们都将元素添加到 arr 中,arr 变为 [3,2,5,4] 。
+
+ +

示例 2:

+ +
+输入:nums = [2,5]
+输出:[5,2]
+解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 5 。然后 Bob 先将 5 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [5,2] 。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 1 <= nums[i] <= 100
  • +
  • nums.length % 2 == 0
  • +
+ +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2974.Minimum Number Game/README_EN.md b/solution/2900-2999/2974.Minimum Number Game/README_EN.md new file mode 100644 index 0000000000000..d8a36fe3a6a22 --- /dev/null +++ b/solution/2900-2999/2974.Minimum Number Game/README_EN.md @@ -0,0 +1,78 @@ +# [2974. Minimum Number Game](https://leetcode.com/problems/minimum-number-game) + +[中文文档](/solution/2900-2999/2974.Minimum%20Number%20Game/README.md) + +## Description + +

You are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:

+ +
    +
  • Every round, first Alice will remove the minimum element from nums, and then Bob does the same.
  • +
  • Now, first Bob will append the removed element in the array arr, and then Alice does the same.
  • +
  • The game continues until nums becomes empty.
  • +
+ +

Return the resulting array arr.

+ +

 

+

Example 1:

+ +
+Input: nums = [5,4,2,3]
+Output: [3,2,5,4]
+Explanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2].
+At the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].
+
+ +

Example 2:

+ +
+Input: nums = [2,5]
+Output: [5,2]
+Explanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= nums.length <= 100
  • +
  • 1 <= nums[i] <= 100
  • +
  • nums.length % 2 == 0
  • +
+ +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md new file mode 100644 index 0000000000000..e96298a7c7a41 --- /dev/null +++ b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md @@ -0,0 +1,93 @@ +# [2975. 移除栅栏得到的正方形田地的最大面积](https://leetcode.cn/problems/maximum-square-area-by-removing-fences-from-a-field) + +[English Version](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README_EN.md) + +## 题目描述 + + + +

有一个大型的 (m - 1) x (n - 1) 矩形田地,其两个对角分别是 (1, 1)(m, n) ,田地内部有一些水平栅栏和垂直栅栏,分别由数组 hFencesvFences 给出。

+ +

水平栅栏为坐标 (hFences[i], 1)(hFences[i], n),垂直栅栏为坐标 (1, vFences[i])(m, vFences[i])

+ +

返回通过 移除 一些栅栏(可能不移除)所能形成的最大面积的 正方形 田地的面积,或者如果无法形成正方形田地则返回 -1

+ +

由于答案可能很大,所以请返回结果对 109 + 7 取余 后的值。

+ +

注意:田地外围两个水平栅栏(坐标 (1, 1)(1, n) 和坐标 (m, 1)(m, n) )以及两个垂直栅栏(坐标 (1, 1)(m, 1) 和坐标 (1, n)(m, n) )所包围。这些栅栏 不能 被移除。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:m = 4, n = 3, hFences = [2,3], vFences = [2]
+输出:4
+解释:移除位于 2 的水平栅栏和位于 2 的垂直栅栏将得到一个面积为 4 的正方形田地。
+
+ +

示例 2:

+ +

+ +
+输入:m = 6, n = 7, hFences = [2], vFences = [4]
+输出:-1
+解释:可以证明无法通过移除栅栏形成正方形田地。
+
+ +

 

+ +

提示:

+ +
    +
  • 3 <= m, n <= 109
  • +
  • 1 <= hFences.length, vFences.length <= 600
  • +
  • 1 < hFences[i] < m
  • +
  • 1 < vFences[i] < n
  • +
  • hFencesvFences 中的元素是唯一的。
  • +
+ +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md new file mode 100644 index 0000000000000..e7b8403134b6c --- /dev/null +++ b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md @@ -0,0 +1,83 @@ +# [2975. Maximum Square Area by Removing Fences From a Field](https://leetcode.com/problems/maximum-square-area-by-removing-fences-from-a-field) + +[中文文档](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README.md) + +## Description + +

There is a large (m - 1) x (n - 1) rectangular field with corners at (1, 1) and (m, n) containing some horizontal and vertical fences given in arrays hFences and vFences respectively.

+ +

Horizontal fences are from the coordinates (hFences[i], 1) to (hFences[i], n) and vertical fences are from the coordinates (1, vFences[i]) to (m, vFences[i]).

+ +

Return the maximum area of a square field that can be formed by removing some fences (possibly none) or -1 if it is impossible to make a square field.

+ +

Since the answer may be large, return it modulo 109 + 7.

+ +

Note: The field is surrounded by two horizontal fences from the coordinates (1, 1) to (1, n) and (m, 1) to (m, n) and two vertical fences from the coordinates (1, 1) to (m, 1) and (1, n) to (m, n). These fences cannot be removed.

+ +

 

+

Example 1:

+ +

+ +
+Input: m = 4, n = 3, hFences = [2,3], vFences = [2]
+Output: 4
+Explanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.
+
+ +

Example 2:

+ +

+ +
+Input: m = 6, n = 7, hFences = [2], vFences = [4]
+Output: -1
+Explanation: It can be proved that there is no way to create a square field by removing fences.
+
+ +

 

+

Constraints:

+ +
    +
  • 3 <= m, n <= 109
  • +
  • 1 <= hFences.length, vFences.length <= 600
  • +
  • 1 < hFences[i] < m
  • +
  • 1 < vFences[i] < n
  • +
  • hFences and vFences are unique.
  • +
+ +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/maxsquareareaexample1.png b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/maxsquareareaexample1.png new file mode 100644 index 0000000000000000000000000000000000000000..7835931681483ea5e4875d331bf5383709f89ea5 GIT binary patch literal 5300 zcmeHLc~q0vwogK=NG;ZRM6DV{6q@9NghZ>5km<{ukP)Xq=6U!6Nh+FnYjL_>6%?lk zdWonwUBwZVRK40(g*IsGRH3C;R-C}9718QDTzzl7`~K)3@2&gKTU}Y-8TL76?{oI~ zo!{Oo%S8g#2T7xnP$<*~9Cn@rg+ix*_AiO=fzml(;6_lPJrWiTwZCah9EIw05Md}0 zn@?}D>QFd{{9lX>5b;DP zoj^z@67vZV4$93Ug90LDK*UV-+xZ%U&i+mz-w`lbtr{GWnU#SDs#5uyB9k3)c#JrR z2KpR3qO*b;h(Rfof5Zx@>0c`}=BHaol}L{56TP9xA+c={~hfLJwb&h z(X&)!;8vPOl&jElnUYM2+Rw@I`?Cltx=2RJ3y|a`}|0JaI8iD^diQ3MHh-|g`Mv;Aw^`ik!~+GgUe)sA&SsU z%T&S^gG&jC07{r5n?!FRQe=fBy&iNkWv~`hHaszqX<+$5(=QUziSk0d$4c@-G>?cT z0H?JvChPE04*i*(iLT$SfC` zWGsnCm2V;m?fN1C7ntVKi!9)POfFkftfO-T`4qKJsrCRp317=fh}uS?Ej`}-uY+XbnMxY=ZipJCGF34LsfO~%e8z%Cl_9@7QOi@98x zsKiUc2eNy~0qTYQe{#k@2?X@tku$_-{PvUWC{*$xPF`-lZ{EZ3++BL_(6Xv;Q&;SK zz&yNa{1=I5ci|5;Z^~G)qq=(K5-j(^XS0?~*uL^ibjz$=Ip?NxmM_bI(-Qxh+V|_O zvn%RHH>_D!v2KDWHSzKJ&r1qNG?|(j?wtO0@3YqCpr~j6n-}{!o_DyKZ=8Fa_iu(*Gd2CXBA5mPmSn)hMs@FHOeTvBF?2A=(8IA zJ*F}>d`|xTBhR?Lvl==3kek;ot_*gD2fp-2#cgZtu@eKk+f0|bYg#&K+tMFD3C%`7 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)s7wyDY{>RGURlgoJ_gr}VFnT3g7wW{cJpc6QZxN8# zfA{kfxRxWHaUR58>8VEaa7-m?09t`=#XL%wH|Wa)AQPdkN)0EcKiuG&8o!M`m5}}H z=)FLjCmN0xV5W7Kx!$EJtY0r3?`)lUiP%D3TMOy_f?>Vkf6+Y5 zCyAFQho6vJFH&4L?~pMq<3=o;8KuRs)szXL_j=Rp-E%)iW%L<~eSIPU6*-(RlZ6v) zj6R5MvM4}O%xPYmla7IF<>Pj)jdp=lwrglZHP$>Zby`@xkv9?DuV&D)Q$*nhKmRyr zP4qe#zy90FF!pPZ{QV=1um*c!GDzqiegANhXmv0)Rk1uY2~P^W!DL!q&*^DPpo705 OQ5=RKZ$E9plK%kPH}*^b literal 0 HcmV?d00001 diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/screenshot-from-2023-11-05-22-40-25.png b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/screenshot-from-2023-11-05-22-40-25.png new file mode 100644 index 0000000000000000000000000000000000000000..c9fcb790c7bf06ea432069ae80fd78bed705b154 GIT binary patch literal 5058 zcmbVQcT`i$y5E!=K#78=KoE!&J&N?ut4I}rgMc&%N{3LT7<#irfq)bd5m4}eC>^9o z7bGCkTOgDO(hQLf(&SCwC`8GdGx!X4*Uq>2n0cJJzdS~ z5JZ;_p2wMC;5)aB^%?kK^wrQaWd@%RW(OQ7bNgvo_?dV)`Q5#J#}RV&^zv{N^|im_ z=;-O|;^nu@(5MO;iMg6u_+7cfs0~A*eU8FA^ysgY2#EZRm?fN=Zmb zBc-GiQ4)$$GJBn&2ngap=xJUy#lE0UgkDS8JS41+G*7ErOr{9WCHz+4__WjW=2PbK zOV;`6AC@LZCx+wZ3Y^4TM?dTcQqv0!DDj`mhU1bDuVXd)@-NqDZ^=Gp-Gw_6IN5=iQwOHBYQ?9XQuH(EM&|c}l!-s`&BaBL>e= z9b57&U4sbkL~DkvA#>YMVen6ii1`@bA4dCOjc?z*Q}TF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lQ|l}ML(a+_)GII?x z-jY0P4T>9f-%_G~0;MK_lqn@CX=c|yt(Qn7QY*1(ht;8bTcdn*lI_EY-)(Go@7i8j zEy~SpYxik++(py9;o%#F=z6Q6p&@OU&zZc=N>Jf3SvT6gsdWX(hNJ96&bSxSb#--x zzymegiQtYvn?GbFa=5@U=XT43`v;GnW@Q!U=)^xz0Wq$Fa{QdkH}wku)os2z<2L{C zA9`1(wPGF>RAHJDh4oJ|Gk$EyYy=ko_b^S((M)D&G~d=LnGd*pj<$1LtlwWf950oxT&nRas(~BdWZ`7xgxe4yfd3hA(qMG5d_t9+ zoZQ3EOVvPEJGYoiUW;RzXnJ!?f@{kkER80UppA@-ma^Ko&ySkt;k73je4e^^jfnpira^v37B2|SwJ|6;KZZHNc z5nrv&5GXV*02Wec8S&JgGMo>*SoSiGtO|}dM(l&Gw9}Uol_Pesi!x;3^lku(t?K!T z3 + +

给你两个下标从 0 开始的字符串 sourcetarget ,它们的长度均为 n 并且由 小写 英文字母组成。

+ +

另给你两个下标从 0 开始的字符数组 originalchanged ,以及一个整数数组 cost ,其中 cost[i] 代表将字符 original[i] 更改为字符 changed[i] 的成本。

+ +

你从字符串 source 开始。在一次操作中,如果 存在 任意 下标 j 满足 cost[j] == z  、original[j] == x 以及 changed[j] == y 。你就可以选择字符串中的一个字符 x 并以 z 的成本将其更改为字符 y

+ +

返回将字符串 source 转换为字符串 target 所需的 最小 成本。如果不可能完成转换,则返回 -1

+ +

注意,可能存在下标 ij 使得 original[j] == original[i]changed[j] == changed[i]

+ +

 

+ +

示例 1:

+ +
+输入:source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
+输出:28
+解释:将字符串 "abcd" 转换为字符串 "acbe" :
+- 更改下标 1 处的值 'b' 为 'c' ,成本为 5 。
+- 更改下标 2 处的值 'c' 为 'e' ,成本为 1 。
+- 更改下标 2 处的值 'e' 为 'b' ,成本为 2 。
+- 更改下标 3 处的值 'd' 为 'e' ,成本为 20 。
+产生的总成本是 5 + 1 + 2 + 20 = 28 。
+可以证明这是可能的最小成本。
+
+ +

示例 2:

+ +
+输入:source = "aaaa", target = "bbbb", original = ["a","c"], changed = ["c","b"], cost = [1,2]
+输出:12
+解释:要将字符 'a' 更改为 'b':
+- 将字符 'a' 更改为 'c',成本为 1 
+- 将字符 'c' 更改为 'b',成本为 2 
+产生的总成本是 1 + 2 = 3。
+将所有 'a' 更改为 'b',产生的总成本是 3 * 4 = 12 。
+
+ +

示例 3:

+ +
+输入:source = "abcd", target = "abce", original = ["a"], changed = ["e"], cost = [10000]
+输出:-1
+解释:无法将 source 字符串转换为 target 字符串,因为下标 3 处的值无法从 'd' 更改为 'e' 。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= source.length == target.length <= 105
  • +
  • sourcetarget 均由小写英文字母组成
  • +
  • 1 <= cost.length== original.length == changed.length <= 2000
  • +
  • original[i]changed[i] 是小写英文字母
  • +
  • 1 <= cost[i] <= 106
  • +
  • original[i] != changed[i]
  • +
+ +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md b/solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md new file mode 100644 index 0000000000000..f0f94ab66a4fe --- /dev/null +++ b/solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md @@ -0,0 +1,92 @@ +# [2976. Minimum Cost to Convert String I](https://leetcode.com/problems/minimum-cost-to-convert-string-i) + +[中文文档](/solution/2900-2999/2976.Minimum%20Cost%20to%20Convert%20String%20I/README.md) + +## Description + +

You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters. You are also given two 0-indexed character arrays original and changed, and an integer array cost, where cost[i] represents the cost of changing the character original[i] to the character changed[i].

+ +

You start with the string source. In one operation, you can pick a character x from the string and change it to the character y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y.

+ +

Return the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.

+ +

Note that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].

+ +

 

+

Example 1:

+ +
+Input: source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
+Output: 28
+Explanation: To convert the string "abcd" to string "acbe":
+- Change value at index 1 from 'b' to 'c' at a cost of 5.
+- Change value at index 2 from 'c' to 'e' at a cost of 1.
+- Change value at index 2 from 'e' to 'b' at a cost of 2.
+- Change value at index 3 from 'd' to 'e' at a cost of 20.
+The total cost incurred is 5 + 1 + 2 + 20 = 28.
+It can be shown that this is the minimum possible cost.
+
+ +

Example 2:

+ +
+Input: source = "aaaa", target = "bbbb", original = ["a","c"], changed = ["c","b"], cost = [1,2]
+Output: 12
+Explanation: To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.
+
+ +

Example 3:

+ +
+Input: source = "abcd", target = "abce", original = ["a"], changed = ["e"], cost = [10000]
+Output: -1
+Explanation: It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= source.length == target.length <= 105
  • +
  • source, target consist of lowercase English letters.
  • +
  • 1 <= cost.length == original.length == changed.length <= 2000
  • +
  • original[i], changed[i] are lowercase English letters.
  • +
  • 1 <= cost[i] <= 106
  • +
  • original[i] != changed[i]
  • +
+ +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2977.Minimum Cost to Convert String II/README.md b/solution/2900-2999/2977.Minimum Cost to Convert String II/README.md new file mode 100644 index 0000000000000..b90c0154faeff --- /dev/null +++ b/solution/2900-2999/2977.Minimum Cost to Convert String II/README.md @@ -0,0 +1,117 @@ +# [2977. 转换字符串的最小成本 II](https://leetcode.cn/problems/minimum-cost-to-convert-string-ii) + +[English Version](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README_EN.md) + +## 题目描述 + + + +

给你两个下标从 0 开始的字符串 sourcetarget ,它们的长度均为 n 并且由 小写 英文字母组成。

+ +

另给你两个下标从 0 开始的字符串数组 originalchanged ,以及一个整数数组 cost ,其中 cost[i] 代表将字符串 original[i] 更改为字符串 changed[i] 的成本。

+ +

你从字符串 source 开始。在一次操作中,如果 存在 任意 下标 j 满足 cost[j] == z  、original[j] == x 以及 changed[j] == y ,你就可以选择字符串中的 子串 x 并以 z 的成本将其更改为 y 。 你可以执行 任意数量 的操作,但是任两次操作必须满足 以下两个 条件 之一

+ +
    +
  • 在两次操作中选择的子串分别是 source[a..b]source[c..d] ,满足 b < c  d < a 。换句话说,两次操作中选择的下标 不相交
  • +
  • 在两次操作中选择的子串分别是 source[a..b]source[c..d] ,满足 a == c b == d 。换句话说,两次操作中选择的下标 相同
  • +
+ +

返回将字符串 source 转换为字符串 target 所需的 最小 成本。如果不可能完成转换,则返回 -1

+ +

注意,可能存在下标 ij 使得 original[j] == original[i]changed[j] == changed[i]

+ +

 

+ +

示例 1:

+ +
+输入:source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
+输出:28
+解释:将 "abcd" 转换为 "acbe",执行以下操作:
+- 将子串 source[1..1] 从 "b" 改为 "c" ,成本为 5 。
+- 将子串 source[2..2] 从 "c" 改为 "e" ,成本为 1 。
+- 将子串 source[2..2] 从 "e" 改为 "b" ,成本为 2 。
+- 将子串 source[3..3] 从 "d" 改为 "e" ,成本为 20 。
+产生的总成本是 5 + 1 + 2 + 20 = 28 。 
+可以证明这是可能的最小成本。
+
+ +

示例 2:

+ +
+输入:source = "abcdefgh", target = "acdeeghh", original = ["bcd","fgh","thh"], changed = ["cde","thh","ghh"], cost = [1,3,5]
+输出:9
+解释:将 "abcdefgh" 转换为 "acdeeghh",执行以下操作:
+- 将子串 source[1..3] 从 "bcd" 改为 "cde" ,成本为 1 。
+- 将子串 source[5..7] 从 "fgh" 改为 "thh" ,成本为 3 。可以执行此操作,因为下标 [5,7] 与第一次操作选中的下标不相交。
+- 将子串 source[5..7] 从 "thh" 改为 "ghh" ,成本为 5 。可以执行此操作,因为下标 [5,7] 与第一次操作选中的下标不相交,且与第二次操作选中的下标相同。
+产生的总成本是 1 + 3 + 5 = 9 。
+可以证明这是可能的最小成本。
+
+ +

示例 3:

+ +
+输入:source = "abcdefgh", target = "addddddd", original = ["bcd","defgh"], changed = ["ddd","ddddd"], cost = [100,1578]
+输出:-1
+解释:无法将 "abcdefgh" 转换为 "addddddd" 。
+如果选择子串 source[1..3] 执行第一次操作,以将 "abcdefgh" 改为 "adddefgh" ,你无法选择子串 source[3..7] 执行第二次操作,因为两次操作有一个共用下标 3 。
+如果选择子串 source[3..7] 执行第一次操作,以将 "abcdefgh" 改为 "abcddddd" ,你无法选择子串 source[1..3] 执行第二次操作,因为两次操作有一个共用下标 3 。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= source.length == target.length <= 1000
  • +
  • sourcetarget 均由小写英文字母组成
  • +
  • 1 <= cost.length == original.length == changed.length <= 100
  • +
  • 1 <= original[i].length == changed[i].length <= source.length
  • +
  • original[i]changed[i] 均由小写英文字母组成
  • +
  • original[i] != changed[i]
  • +
  • 1 <= cost[i] <= 106
  • +
+ +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md b/solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md new file mode 100644 index 0000000000000..4053fc6256e8e --- /dev/null +++ b/solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md @@ -0,0 +1,105 @@ +# [2977. Minimum Cost to Convert String II](https://leetcode.com/problems/minimum-cost-to-convert-string-ii) + +[中文文档](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README.md) + +## Description + +

You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English characters. You are also given two 0-indexed string arrays original and changed, and an integer array cost, where cost[i] represents the cost of converting the string original[i] to the string changed[i].

+ +

You start with the string source. In one operation, you can pick a substring x from the string, and change it to y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y. You are allowed to do any number of operations, but any pair of operations must satisfy either of these two conditions:

+ +
    +
  • The substrings picked in the operations are source[a..b] and source[c..d] with either b < c or d < a. In other words, the indices picked in both operations are disjoint.
  • +
  • The substrings picked in the operations are source[a..b] and source[c..d] with a == c and b == d. In other words, the indices picked in both operations are identical.
  • +
+ +

Return the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.

+ +

Note that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].

+ +

 

+

Example 1:

+ +
+Input: source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
+Output: 28
+Explanation: To convert "abcd" to "acbe", do the following operations:
+- Change substring source[1..1] from "b" to "c" at a cost of 5.
+- Change substring source[2..2] from "c" to "e" at a cost of 1.
+- Change substring source[2..2] from "e" to "b" at a cost of 2.
+- Change substring source[3..3] from "d" to "e" at a cost of 20.
+The total cost incurred is 5 + 1 + 2 + 20 = 28. 
+It can be shown that this is the minimum possible cost.
+
+ +

Example 2:

+ +
+Input: source = "abcdefgh", target = "acdeeghh", original = ["bcd","fgh","thh"], changed = ["cde","thh","ghh"], cost = [1,3,5]
+Output: 9
+Explanation: To convert "abcdefgh" to "acdeeghh", do the following operations:
+- Change substring source[1..3] from "bcd" to "cde" at a cost of 1.
+- Change substring source[5..7] from "fgh" to "thh" at a cost of 3. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation.
+- Change substring source[5..7] from "thh" to "ghh" at a cost of 5. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation, and identical with indices picked in the second operation.
+The total cost incurred is 1 + 3 + 5 = 9.
+It can be shown that this is the minimum possible cost.
+
+ +

Example 3:

+ +
+Input: source = "abcdefgh", target = "addddddd", original = ["bcd","defgh"], changed = ["ddd","ddddd"], cost = [100,1578]
+Output: -1
+Explanation: It is impossible to convert "abcdefgh" to "addddddd".
+If you select substring source[1..3] as the first operation to change "abcdefgh" to "adddefgh", you cannot select substring source[3..7] as the second operation because it has a common index, 3, with the first operation.
+If you select substring source[3..7] as the first operation to change "abcdefgh" to "abcddddd", you cannot select substring source[1..3] as the second operation because it has a common index, 3, with the first operation.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= source.length == target.length <= 1000
  • +
  • source, target consist only of lowercase English characters.
  • +
  • 1 <= cost.length == original.length == changed.length <= 100
  • +
  • 1 <= original[i].length == changed[i].length <= source.length
  • +
  • original[i], changed[i] consist only of lowercase English characters.
  • +
  • original[i] != changed[i]
  • +
  • 1 <= cost[i] <= 106
  • +
+ +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/CONTEST_README.md b/solution/CONTEST_README.md index 83bb50b407d12..4c302a2cace2d 100644 --- a/solution/CONTEST_README.md +++ b/solution/CONTEST_README.md @@ -22,12 +22,19 @@ ## 往期竞赛 +#### 第 377 场周赛(2023-12-24 10:30, 90 分钟) 参赛人数 3148 + +- [2974. 最小数字游戏](/solution/2900-2999/2974.Minimum%20Number%20Game/README.md) +- [2975. 移除栅栏得到的正方形田地的最大面积](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README.md) +- [2976. 转换字符串的最小成本 I](/solution/2900-2999/2976.Minimum%20Cost%20to%20Convert%20String%20I/README.md) +- [2977. 转换字符串的最小成本 II](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README.md) + #### 第 120 场双周赛(2023-12-23 22:30, 90 分钟) 参赛人数 2542 -- [10031. 统计移除递增子数组的数目 I](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) -- [10032. 找到最大周长的多边形](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) -- [10033. 统计移除递增子数组的数目 II](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) -- [10034. 树中每个节点放置的金币数目](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md) +- [2970. 统计移除递增子数组的数目 I](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) +- [2971. 找到最大周长的多边形](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) +- [2972. 统计移除递增子数组的数目 II](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) +- [2973. 树中每个节点放置的金币数目](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md) #### 第 376 场周赛(2023-12-17 10:30, 90 分钟) 参赛人数 3409 diff --git a/solution/CONTEST_README_EN.md b/solution/CONTEST_README_EN.md index 0379771287386..6f0453b019c1a 100644 --- a/solution/CONTEST_README_EN.md +++ b/solution/CONTEST_README_EN.md @@ -25,12 +25,19 @@ Get your rating changes right after the completion of LeetCode contests, https:/ ## Past Contests +#### Weekly Contest 377 + +- [2974. Minimum Number Game](/solution/2900-2999/2974.Minimum%20Number%20Game/README_EN.md) +- [2975. Maximum Square Area by Removing Fences From a Field](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README_EN.md) +- [2976. Minimum Cost to Convert String I](/solution/2900-2999/2976.Minimum%20Cost%20to%20Convert%20String%20I/README_EN.md) +- [2977. Minimum Cost to Convert String II](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README_EN.md) + #### Biweekly Contest 120 -- [10031. Count the Number of Incremovable Subarrays I](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) -- [10032. Find Polygon With the Largest Perimeter](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) -- [10033. Count the Number of Incremovable Subarrays II](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) -- [10034. Find Number of Coins to Place in Tree Nodes](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) +- [2970. Count the Number of Incremovable Subarrays I](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) +- [2971. Find Polygon With the Largest Perimeter](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) +- [2972. Count the Number of Incremovable Subarrays II](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) +- [2973. Find Number of Coins to Place in Tree Nodes](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) #### Weekly Contest 376 diff --git a/solution/README.md b/solution/README.md index 8e0b2f671e77e..6630cac23523d 100644 --- a/solution/README.md +++ b/solution/README.md @@ -1014,10 +1014,6 @@ | 1001 | [网格照明](/solution/1000-1099/1001.Grid%20Illumination/README.md) | `数组`,`哈希表` | 困难 | 第 125 场周赛 | | 1002 | [查找共用字符](/solution/1000-1099/1002.Find%20Common%20Characters/README.md) | `数组`,`哈希表`,`字符串` | 简单 | 第 126 场周赛 | | 1003 | [检查替换后的词是否有效](/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README.md) | `栈`,`字符串` | 中等 | 第 126 场周赛 | -| 10031 | [统计移除递增子数组的数目 I](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) | | 简单 | 第 120 场双周赛 | -| 10032 | [找到最大周长的多边形](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) | | 中等 | 第 120 场双周赛 | -| 10033 | [统计移除递增子数组的数目 II](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) | | 困难 | 第 120 场双周赛 | -| 10034 | [树中每个节点放置的金币数目](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md) | | 困难 | 第 120 场双周赛 | | 1004 | [最大连续1的个数 III](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README.md) | `数组`,`二分查找`,`前缀和`,`滑动窗口` | 中等 | 第 126 场周赛 | | 1005 | [K 次取反后最大化的数组和](/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README.md) | `贪心`,`数组`,`排序` | 简单 | 第 127 场周赛 | | 1006 | [笨阶乘](/solution/1000-1099/1006.Clumsy%20Factorial/README.md) | `栈`,`数学`,`模拟` | 中等 | 第 127 场周赛 | @@ -2978,12 +2974,20 @@ | 2961 | [双模幂运算](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md) | `数组`,`数学`,`模拟` | 中等 | 第 375 场周赛 | | 2962 | [统计最大元素出现至少 K 次的子数组](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md) | `数组`,`滑动窗口` | 中等 | 第 375 场周赛 | | 2963 | [统计好分割方案的数目](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md) | `数组`,`哈希表`,`数学`,`组合数学` | 困难 | 第 375 场周赛 | -| 2964 | [Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README.md) | | 中等 | 🔒 | -| 2965 | [找出缺失和重复的数字](/solution/2900-2999/2965.Find%20Missing%20and%20Repeated%20Values/README.md) | | 简单 | 第 376 场周赛 | +| 2964 | [Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README.md) | `数组`,`哈希表` | 中等 | 🔒 | +| 2965 | [找出缺失和重复的数字](/solution/2900-2999/2965.Find%20Missing%20and%20Repeated%20Values/README.md) | `数组`,`哈希表`,`数学`,`矩阵` | 简单 | 第 376 场周赛 | | 2966 | [划分数组并满足最大差限制](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README.md) | | 中等 | 第 376 场周赛 | -| 2967 | [使数组成为等数数组的最小代价](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README.md) | | 中等 | 第 376 场周赛 | -| 2968 | [执行操作使频率分数最大](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README.md) | | 困难 | 第 376 场周赛 | -| 2969 | [Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README.md) | | 困难 | 🔒 | +| 2967 | [使数组成为等数数组的最小代价](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README.md) | `贪心`,`数组`,`数学`,`排序` | 中等 | 第 376 场周赛 | +| 2968 | [执行操作使频率分数最大](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README.md) | `数组`,`二分查找`,`前缀和`,`排序`,`滑动窗口` | 困难 | 第 376 场周赛 | +| 2969 | [购买水果需要的最少金币数 II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README.md) | `队列`,`数组`,`动态规划`,`单调队列` | 困难 | 🔒 | +| 2970 | [统计移除递增子数组的数目 I](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) | | 简单 | 第 120 场双周赛 | +| 2971 | [找到最大周长的多边形](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) | | 中等 | 第 120 场双周赛 | +| 2972 | [统计移除递增子数组的数目 II](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) | | 困难 | 第 120 场双周赛 | +| 2973 | [树中每个节点放置的金币数目](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md) | | 困难 | 第 120 场双周赛 | +| 2974 | [最小数字游戏](/solution/2900-2999/2974.Minimum%20Number%20Game/README.md) | | 简单 | 第 377 场周赛 | +| 2975 | [移除栅栏得到的正方形田地的最大面积](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README.md) | | 中等 | 第 377 场周赛 | +| 2976 | [转换字符串的最小成本 I](/solution/2900-2999/2976.Minimum%20Cost%20to%20Convert%20String%20I/README.md) | | 中等 | 第 377 场周赛 | +| 2977 | [转换字符串的最小成本 II](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README.md) | | 困难 | 第 377 场周赛 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 230266e390992..aaf2d64be01e8 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -1012,10 +1012,6 @@ Press Control + F(or Command + F on | 1001 | [Grid Illumination](/solution/1000-1099/1001.Grid%20Illumination/README_EN.md) | `Array`,`Hash Table` | Hard | Weekly Contest 125 | | 1002 | [Find Common Characters](/solution/1000-1099/1002.Find%20Common%20Characters/README_EN.md) | `Array`,`Hash Table`,`String` | Easy | Weekly Contest 126 | | 1003 | [Check If Word Is Valid After Substitutions](/solution/1000-1099/1003.Check%20If%20Word%20Is%20Valid%20After%20Substitutions/README_EN.md) | `Stack`,`String` | Medium | Weekly Contest 126 | -| 10031 | [Count the Number of Incremovable Subarrays I](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) | | Easy | Biweekly Contest 120 | -| 10032 | [Find Polygon With the Largest Perimeter](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) | | Medium | Biweekly Contest 120 | -| 10033 | [Count the Number of Incremovable Subarrays II](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) | | Hard | Biweekly Contest 120 | -| 10034 | [Find Number of Coins to Place in Tree Nodes](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) | | Hard | Biweekly Contest 120 | | 1004 | [Max Consecutive Ones III](/solution/1000-1099/1004.Max%20Consecutive%20Ones%20III/README_EN.md) | `Array`,`Binary Search`,`Prefix Sum`,`Sliding Window` | Medium | Weekly Contest 126 | | 1005 | [Maximize Sum Of Array After K Negations](/solution/1000-1099/1005.Maximize%20Sum%20Of%20Array%20After%20K%20Negations/README_EN.md) | `Greedy`,`Array`,`Sorting` | Easy | Weekly Contest 127 | | 1006 | [Clumsy Factorial](/solution/1000-1099/1006.Clumsy%20Factorial/README_EN.md) | `Stack`,`Math`,`Simulation` | Medium | Weekly Contest 127 | @@ -2976,12 +2972,20 @@ Press Control + F(or Command + F on | 2961 | [Double Modular Exponentiation](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md) | `Array`,`Math`,`Simulation` | Medium | Weekly Contest 375 | | 2962 | [Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) | `Array`,`Sliding Window` | Medium | Weekly Contest 375 | | 2963 | [Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) | `Array`,`Hash Table`,`Math`,`Combinatorics` | Hard | Weekly Contest 375 | -| 2964 | [Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README_EN.md) | | Medium | 🔒 | -| 2965 | [Find Missing and Repeated Values](/solution/2900-2999/2965.Find%20Missing%20and%20Repeated%20Values/README_EN.md) | | Easy | Weekly Contest 376 | +| 2964 | [Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README_EN.md) | `Array`,`Hash Table` | Medium | 🔒 | +| 2965 | [Find Missing and Repeated Values](/solution/2900-2999/2965.Find%20Missing%20and%20Repeated%20Values/README_EN.md) | `Array`,`Hash Table`,`Math`,`Matrix` | Easy | Weekly Contest 376 | | 2966 | [Divide Array Into Arrays With Max Difference](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README_EN.md) | | Medium | Weekly Contest 376 | -| 2967 | [Minimum Cost to Make Array Equalindromic](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README_EN.md) | | Medium | Weekly Contest 376 | -| 2968 | [Apply Operations to Maximize Frequency Score](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README_EN.md) | | Hard | Weekly Contest 376 | -| 2969 | [Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README_EN.md) | | Hard | 🔒 | +| 2967 | [Minimum Cost to Make Array Equalindromic](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README_EN.md) | `Greedy`,`Array`,`Math`,`Sorting` | Medium | Weekly Contest 376 | +| 2968 | [Apply Operations to Maximize Frequency Score](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README_EN.md) | `Array`,`Binary Search`,`Prefix Sum`,`Sorting`,`Sliding Window` | Hard | Weekly Contest 376 | +| 2969 | [Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README_EN.md) | `Queue`,`Array`,`Dynamic Programming`,`Monotonic Queue` | Hard | 🔒 | +| 2970 | [Count the Number of Incremovable Subarrays I](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) | | Easy | Biweekly Contest 120 | +| 2971 | [Find Polygon With the Largest Perimeter](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) | | Medium | Biweekly Contest 120 | +| 2972 | [Count the Number of Incremovable Subarrays II](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) | | Hard | Biweekly Contest 120 | +| 2973 | [Find Number of Coins to Place in Tree Nodes](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) | | Hard | Biweekly Contest 120 | +| 2974 | [Minimum Number Game](/solution/2900-2999/2974.Minimum%20Number%20Game/README_EN.md) | | Easy | Weekly Contest 377 | +| 2975 | [Maximum Square Area by Removing Fences From a Field](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README_EN.md) | | Medium | Weekly Contest 377 | +| 2976 | [Minimum Cost to Convert String I](/solution/2900-2999/2976.Minimum%20Cost%20to%20Convert%20String%20I/README_EN.md) | | Medium | Weekly Contest 377 | +| 2977 | [Minimum Cost to Convert String II](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README_EN.md) | | Hard | Weekly Contest 377 | ## Copyright diff --git a/solution/main.py b/solution/main.py index b4d1c0ee449a5..64bf35f00be21 100644 --- a/solution/main.py +++ b/solution/main.py @@ -365,7 +365,7 @@ def run(): for q in spider.get_all_questions(retry=6): slug = q["stat"]["question__title_slug"] qid = q["stat"]["frontend_question_id"] - if slug in question_details: + if slug in question_details and qid < 2960: continue detail = spider.get_question_detail( slug, retry=4 diff --git a/solution/summary.md b/solution/summary.md index 8c30513814f93..7f895c0bb8f8d 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -3032,4 +3032,12 @@ - [2966.划分数组并满足最大差限制](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README.md) - [2967.使数组成为等数数组的最小代价](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README.md) - [2968.执行操作使频率分数最大](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README.md) - - [2969.Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README.md) + - [2969.购买水果需要的最少金币数 II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README.md) + - [2970.统计移除递增子数组的数目 I](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) + - [2971.找到最大周长的多边形](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) + - [2972.统计移除递增子数组的数目 II](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) + - [2973.树中每个节点放置的金币数目](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md) + - [2974.最小数字游戏](/solution/2900-2999/2974.Minimum%20Number%20Game/README.md) + - [2975.移除栅栏得到的正方形田地的最大面积](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README.md) + - [2976.转换字符串的最小成本 I](/solution/2900-2999/2976.Minimum%20Cost%20to%20Convert%20String%20I/README.md) + - [2977.转换字符串的最小成本 II](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README.md) diff --git a/solution/summary_en.md b/solution/summary_en.md index 646f1de37119e..26e0e1c92cf58 100644 --- a/solution/summary_en.md +++ b/solution/summary_en.md @@ -3033,3 +3033,11 @@ - [2967.Minimum Cost to Make Array Equalindromic](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README_EN.md) - [2968.Apply Operations to Maximize Frequency Score](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README_EN.md) - [2969.Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README_EN.md) + - [2970.Count the Number of Incremovable Subarrays I](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) + - [2971.Find Polygon With the Largest Perimeter](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) + - [2972.Count the Number of Incremovable Subarrays II](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) + - [2973.Find Number of Coins to Place in Tree Nodes](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) + - [2974.Minimum Number Game](/solution/2900-2999/2974.Minimum%20Number%20Game/README_EN.md) + - [2975.Maximum Square Area by Removing Fences From a Field](/solution/2900-2999/2975.Maximum%20Square%20Area%20by%20Removing%20Fences%20From%20a%20Field/README_EN.md) + - [2976.Minimum Cost to Convert String I](/solution/2900-2999/2976.Minimum%20Cost%20to%20Convert%20String%20I/README_EN.md) + - [2977.Minimum Cost to Convert String II](/solution/2900-2999/2977.Minimum%20Cost%20to%20Convert%20String%20II/README_EN.md) From bbd6f0e91149d429fcc43951c55e60089b4a113b Mon Sep 17 00:00:00 2001 From: Doocs Bot Date: Sun, 24 Dec 2023 16:46:59 +0800 Subject: [PATCH 2/2] Optimised images with calibre/image-actions --- .../images/maxsquareareaexample1.png | Bin 5300 -> 1675 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/maxsquareareaexample1.png b/solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/maxsquareareaexample1.png index 7835931681483ea5e4875d331bf5383709f89ea5..f7dd957fc145e0b8b9d287c58367bcad966e4fad 100644 GIT binary patch literal 1675 zcmeAS@N?(olHy`uVBq!ia0y~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