Skip to content

Commit cf4548b

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 91d2136 commit cf4548b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+271
-269
lines changed

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ CODE_OF_CONDUCT.md
77
coverage
88
src/gatsby/xdm.js
99
PULL_REQUEST_TEMPLATE.md
10-
*.mdx
10+
*.mdx

content/3_Silver/Intro_Tree.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public class Subordinates {
183183

184184
In the Python solution, we need to set recursion limit to $2\times10^5$.
185185

186-
```python
186+
```py
187187
import sys
188188
189189
sys.setrecursionlimit(200006) # set recursion limit

content/3_Silver/Prefix_Sums.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public class Main {
272272
273273
<PySection>
274274
275-
```python
275+
```py
276276
def psum(a):
277277
psum = [0]
278278
for i in a:

content/5_Plat/Matrix_Expo.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int main() {
132132
</CPPSection>
133133
134134
<PySection>
135-
```python
135+
```py
136136
from typing import List
137137
138138
MOD = 10**9 + 7

py/format_code.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"{" + ", ".join(filter(lambda x: x != "", CLANG_FORMAT_STYLE.split("\n"))) + "}"
2525
)
2626

27+
2728
def lead_white(line):
2829
return len(line) - len(line.lstrip())
2930

@@ -75,15 +76,17 @@ def format_path(path: str):
7576
nlines = []
7677
prog = []
7778
for line in lines:
78-
if line.strip().startswith("```") and len(line.strip()) > 3: # start of lang block
79+
if (
80+
line.strip().startswith("```") and len(line.strip()) > 3
81+
): # start of lang block
7982
lang = line.strip()[3:].strip()
80-
if lang == 'python':
81-
lang = 'py'
82-
if lang not in ['cpp', 'py', 'java']:
83+
if lang == "python":
84+
lang = "py"
85+
if lang not in ["cpp", "py", "java"]:
8386
raise ValueError(f"Unrecognized formatting lang: {line.strip()[3:]}")
8487
nlines.append(f"```{lang}\n")
8588
elif line.strip() == "```":
86-
if lang is not None: # end of lang block
89+
if lang is not None: # end of lang block
8790
if not contains_banned_terms(prog):
8891
prog = [match_indentation(line, prog_line) for prog_line in prog]
8992
prog = format_prog(lang, prog)
@@ -94,9 +97,9 @@ def format_path(path: str):
9497
prog = []
9598
lang = None
9699
nlines.append(line)
97-
elif lang is not None: # program block
100+
elif lang is not None: # program block
98101
prog.append(line)
99-
else: # outside of program block
102+
else: # outside of program block
100103
nlines.append(line)
101104
with open(path, "w") as f:
102105
f.write("".join(nlines))

solutions/bronze/usaco-1109.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ shoelace formula is proved.
3535

3636
## Implementation
3737

38-
```python
38+
```py
3939
def cross_product(p1, p2):
4040
return p1[0] * p2[1] - p2[0] * p1[1]
4141

solutions/silver/ac-GCDOnBlackboard.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ author: Andrew Cheng, Mohammad Nour Massri, David Zhang
99
The problem asks us to find the maximum possible GCD of the remaining $N-1$ numbers
1010
after taking any one of them away. Naively trying every single combination will result in a
1111
complexity of $\mathcal{O}(N^2 + N \log(\max a_i))$ as there are $N$ different ways to take away a number and calculating
12-
the GCD will take $\mathcal{O}(N+\log(\max a_i))$ time per case.
12+
the GCD will take $\mathcal{O}(N+\log(\max a_i))$ time per case.
1313

1414
To speed this process up, we can calculate the GCDs of every prefix and suffix. Let $l[i] = \gcd_{j=1}^{i} a[j]$ and $r[i] = \gcd_{j=i}^{N} a[j]$.
15-
Then the answer is the maximum of $\gcd(l[i-1],r[i+1]),$ $i \in [1,N]$.
15+
Then the answer is the maximum of $\gcd(l[i-1],r[i+1]),$ $i \in [1,N]$.
1616

1717
**Time Complexity:**
1818
$\mathcal{O}(N+\log(\max a_i))$
@@ -107,7 +107,7 @@ print(ans)
107107
```
108108
</PySection>
109109
<JavaSection>
110-
110+
111111
```java
112112
import java.util.*;
113113
import java.io.*;

solutions/silver/ac-MultipleOf2019.mdx

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@ $$[1234, 234, 34, 4, 0]$$
1818

1919
**Keep in mind, that an empty suffix with is also considered.**
2020

21-
This is useful because we can access any substring in $\mathcal{O}(1)$ time through a range query. So if $${S_0} = 1234 $$ and $${S_3=4}$$, this means $${S_0}-{S_3} = 123 * {10^1}$$ or $$1230$$.
21+
This is useful because we can access any substring in $\mathcal{O}(1)$ time through a range query. So if $${S_0} = 1234 $$ and $${S_3=4}$$, this means $${S_0}-{S_3} = 123 * {10^1}$$ or $$1230$$.
2222

23-
It also means that if both $${S_0}(mod$$ $$M)=$$ $${S_3}(mod$$ $$M)$$ (both suffixes have the same remainders), subtracting would lead to $${S_0}(mod$$ $$M)-$$ $${S_3}(mod$$ $$M)=0$$, meaning a substring that is divisible by $$2019$$.
23+
It also means that if both $${S_0}(mod$$ $$M)=$$ $${S_3}(mod$$ $$M)$$ (both suffixes have the same remainders), subtracting would lead to $${S_0}(mod$$ $$M)-$$ $${S_3}(mod$$ $$M)=0$$, meaning a substring that is divisible by $$2019$$.
2424

25-
So with $$1234$$, $${S_0-{S_3}=1234(mod}$$ $$3)-4(mod$$ $$3)=1-1=0$$. Because they substract to zero, it means the substring from index $$0$$ to $$2$$ leads to a number divisible by the modulus. (The substring is $$123$$ which is divisble by 3).
25+
So with $$1234$$, $${S_0-{S_3}=1234(mod}$$ $$3)-4(mod$$ $$3)=1-1=0$$. Because they substract to zero, it means the substring from index $$0$$ to $$2$$ leads to a number divisible by the modulus. (The substring is $$123$$ which is divisble by 3).
2626

2727
However, we would still need to go through every pair of possible suffixes $(i, j)$ which would be $\mathcal{O}(N^2)$.
2828

29-
Instead, **we do not need to know which suffix has a certain remainder, but rather how many suffixes have that certain remainder.**
29+
Instead, **we do not need to know which suffix has a certain remainder, but rather how many suffixes have that certain remainder.**
3030

31-
To elaborate, we can take $${N \choose K}$$, and choose 2 numbers that are divisible by the same remainder of 2019, where $$N=$$ the amount of times a certain remainder occurs, and $$K=$$ 2 (because we are picking 2 indicies $$i$$ and $$j$$).
31+
To elaborate, we can take $${N \choose K}$$, and choose 2 numbers that are divisible by the same remainder of 2019, where $$N=$$ the amount of times a certain remainder occurs, and $$K=$$ 2 (because we are picking 2 indicies $$i$$ and $$j$$).
3232

33-
Therefore, our answer is the counts of all the remainders in an array from $$0...2018$$ and $${N \choose 2}$$.
33+
Therefore, our answer is the counts of all the remainders in an array from $$0...2018$$ and $${N \choose 2}$$.
3434

3535
So in our example with $$1234$$, our new array would look like this:
3636

3737
$$[2, 3, 0]$$
3838

39-
Where each index represents the count of a certain remainder.
39+
Where each index represents the count of a certain remainder.
4040
* There are $$2$$ suffixes with a remainder of $$0$$ when dividing by $$3$$, $$[234, 0]$$
4141
* There are $$3$$ suffixes with a remainder of $$1$$ when dividing by $$3$$, $$[1234, 34, 4]$$
4242
* And there are no suffixes with a remainder of $$2$$
4343

44-
So, the sum of all of these numbers would be $${2 \choose 2} + {3 \choose 2}=1+3=4$$
44+
So, the sum of all of these numbers would be $${2 \choose 2} + {3 \choose 2}=1+3=4$$
4545

4646
If $$N<K$$, it should be $$0$$, since there aren't enough suffixes that can make a pair.
4747

@@ -88,9 +88,9 @@ int main() {
8888
```
8989

9090
</CPPSection>
91-
91+
9292
<JavaSection>
93-
93+
9494
```java
9595
import java.io.*;
9696
import java.util.*;
@@ -123,7 +123,7 @@ public class MultipleOf2019 {
123123
//CodeSnip{Kattio}
124124
}
125125
```
126-
126+
127127
</JavaSection>
128128
<PySection>
129129

solutions/silver/apio-11-TableColoring.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ it simply isn't possible to color the table, the answer is $0$.
6161

6262
### Checking Whether the Answer is $0$
6363

64-
This problem then becomes checking whether there is an cycle with odd weight
64+
This problem then becomes checking whether there is an cycle with odd weight
6565
in the resulting graph, which we can answer efficiently using DSU or DFS.
6666

67-
One way to implement this is as follows. Since each already-colored cell
68-
$(x, y)$ determines whether the colors of the cells $(x, 0)$ and $(0, y)$ are
69-
the same, we can instead split each node in our graph into 2 nodes (one for
67+
One way to implement this is as follows. Since each already-colored cell
68+
$(x, y)$ determines whether the colors of the cells $(x, 0)$ and $(0, y)$ are
69+
the same, we can instead split each node in our graph into 2 nodes (one for
7070
each color) and create edges between nodes with consistent colors.
71-
The answer is $0$ if two new nodes corresponding to the same original node
71+
The answer is $0$ if two new nodes corresponding to the same original node
7272
are in the same connected component.
7373

7474
## Implementation

solutions/silver/cc-AMONGUS2.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: Ryan Chou
66
---
77

88
## Explanation
9-
If we only have two players $x$ and $y$, then we have 4 cases possible cases.
9+
If we only have two players $x$ and $y$, then we have 4 cases possible cases.
1010

1111
* If $x$ vouches for $y$ and $x$ is an imposter, then $y$ must also be an imposter.
1212

solutions/silver/ccc-Firehose.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ int main() {
8787
```
8888
</CPPSection>
8989

90-
</LanguageSection>
90+
</LanguageSection>

solutions/silver/ceoi-12-JobScheduling.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ author: Chuyang Wang
99

1010
## Explanation
1111

12-
To find the minimum possible solution, we can use binary search on the number of machines needed for finishing the jobs within the given deadline. With $M$ requests, the number of needed machines must lie in the range $[1, M]$ as in the worst case where all the requests are given on the last day, we still have $D + 1$ days to process these requests.
12+
To find the minimum possible solution, we can use binary search on the number of machines needed for finishing the jobs within the given deadline. With $M$ requests, the number of needed machines must lie in the range $[1, M]$ as in the worst case where all the requests are given on the last day, we still have $D + 1$ days to process these requests.
1313

14-
For each number of machines being tested, we can check its feasibility in linear time if the given job requests are already sorted in ascending order with respect to the request date. We iterate through each day $i$ from $1$ to $N$ and add requests to the schedule in the sorted order. If there is no available machine left on a certain day $i$ while there are still requests not processed, we move to next day $i+1$ and process these requests. If the day $i$ exceeds the delay limit for the current job being processed, i.e. the request date of the job added with the permitted delay is strictly less than the current day $i$, we can stop iterating as it is not possible to use the giving number of machines to process all the jobs within the deadline. Otherwise, if we have processed all job requests, the number of machines being tested is feasible, and we also found a schedule for these jobs.
14+
For each number of machines being tested, we can check its feasibility in linear time if the given job requests are already sorted in ascending order with respect to the request date. We iterate through each day $i$ from $1$ to $N$ and add requests to the schedule in the sorted order. If there is no available machine left on a certain day $i$ while there are still requests not processed, we move to next day $i+1$ and process these requests. If the day $i$ exceeds the delay limit for the current job being processed, i.e. the request date of the job added with the permitted delay is strictly less than the current day $i$, we can stop iterating as it is not possible to use the giving number of machines to process all the jobs within the deadline. Otherwise, if we have processed all job requests, the number of machines being tested is feasible, and we also found a schedule for these jobs.
1515

1616
## Implementation
1717

solutions/silver/cf-1158A.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ int main() {
9292
```
9393

9494
</CPPSection>
95-
95+
9696
<JavaSection>
97-
97+
9898
```java
9999
import java.io.*;
100100
import java.util.*;
@@ -144,9 +144,9 @@ public class ThePartyAndSweets {
144144
io.close();
145145
}
146146
//CodeSnip{Kattio}
147-
}
147+
}
148148
```
149-
149+
150150
</JavaSection>
151151

152152
</LanguageSection>

solutions/silver/cf-1223C.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ author: Jesse Choe, Kevin Sheng
99

1010
## Explanation
1111

12-
Binary search on the answer for the minimum number of tickets, $t$, to sell to make the total ecological contribution to at least $k$.
12+
Binary search on the answer for the minimum number of tickets, $t$, to sell to make the total ecological contribution to at least $k$.
1313

1414
Let's try to determine the maximum contribution attainable with $t$ tickets.
1515

@@ -89,7 +89,7 @@ int main() {
8989
</CPPSection>
9090

9191
<JavaSection>
92-
92+
9393
### Java Implementation
9494

9595
```java
@@ -163,7 +163,7 @@ public final class SaveNature {
163163
</JavaSection>
164164
165165
<PySection>
166-
166+
167167
### Python Implementation
168168
169169
```py
@@ -211,7 +211,7 @@ for _ in range(int(input())):
211211
lo = mid + 1
212212
print(valid)
213213
```
214-
214+
215215
</PySection>
216216

217217
</LanguageSection>

solutions/silver/cf-1359C.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ author: Jesse Choe
1212

1313
Consider the following observations:
1414

15-
- Case 1: The number of cups of hot water poured is equal to the number of cups of cold water poured. Pouring an equal number of cups of hot and cold water is equivalent to pouring one cup of each.
15+
- Case 1: The number of cups of hot water poured is equal to the number of cups of cold water poured. Pouring an equal number of cups of hot and cold water is equivalent to pouring one cup of each.
1616
- Case 2: Otherwise, there must be exactly one more cup of hot water poured than cold water poured. Thus, there will be $c_i + 1$ cups of hot water and $c_i$ cups of cold water for some $c_i \geq 0$.
1717
- It can be proven, using induction, that the average barrel temperatures when $c_i$ is odd is a monotonically decreasing function. Thus, we can binary search on the maximum number of odd cups $c_i$ which gives a temperature of at least $t$ by checking the odd integers around it.
1818

solutions/silver/cf-1398C.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ import java.util.*;
6868
public class GoodSubarrays {
6969
static long solve(int arrLen, String strArr) {
7070
int[] prefArr = new int[arrLen + 1];
71-
for (int i = 1; i <= arrLen; i++) {
71+
for (int i = 1; i <= arrLen; i++) {
7272
prefArr[i] = strArr.charAt(i - 1) - '0';
7373
}
74-
for (int i = 1; i <= arrLen; i++) {
74+
for (int i = 1; i <= arrLen; i++) {
7575
prefArr[i] += prefArr[i - 1];
7676
}
77-
77+
7878
Map<Integer, Long> sumDist = new HashMap<>();
7979
for (int i = 0; i <= arrLen; i++) {
8080
int val = prefArr[i] - i;
8181
sumDist.put(val, sumDist.getOrDefault(val, 0L) + 1);
8282
}
8383

8484
long goodArrays = 0;
85-
for (long f : sumDist.values()) {
85+
for (long f : sumDist.values()) {
8686
// calculate # of possible unordered pairs with f values of i
8787
goodArrays += f * (f - 1) / 2;
8888
}
@@ -92,7 +92,7 @@ public class GoodSubarrays {
9292
public static void main (String[] args) {
9393
Kattio io = new Kattio();
9494
int t = io.nextInt();
95-
for (int i = 0; i < t; i++) {
95+
for (int i = 0; i < t; i++) {
9696
int arrLen = io.nextInt();
9797
String array = io.next();
9898
io.println(solve(arrLen, array));

solutions/silver/cf-1468D.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: Jesse Choe
88
[Official Editorial](https://codeforces.com/blog/entry/85951)
99

1010
We can initially attempt this problem by figuring out which firecrackers should explode. Obviously, we should attempt to explode the firecrackers with a minimal
11-
detonation time to increase the number of firecrackers exploded before eventually being caught. Also, observe that the firecrackers with a longer detonation
11+
detonation time to increase the number of firecrackers exploded before eventually being caught. Also, observe that the firecrackers with a longer detonation
1212
time should be dropped first.
1313

1414
To find the maximum number of firecrackers before the hooligan gets caught by the guard, sort the detonation times in increasing order and figure out the

solutions/silver/cf-1474C.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: Kevin Sheng, Jesse Choe
77

88
[Official Editorial](https://codeforces.com/blog/entry/86933)
99

10-
# Solution
10+
# Solution
1111

1212
**Time Complexity:** $\mathcal{O}(N^2\log N)$
1313

solutions/silver/cf-321B.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ source: CF
44
title: Ciel and Duel
55
author: Ryan Chou
66
---
7-
7+
88
[Official Analysis (C++)](https://codeforces.com/blog/entry/8192)
99

1010
## Explanation

solutions/silver/cf-847B.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main() {
6161
```
6262
</CPPSection>
6363
<PySection>
64-
64+
6565
```py
6666
n = int(input().strip())
6767
numbers = [int(x) for x in input().strip().split()]

0 commit comments

Comments
 (0)