You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solutions/silver/ac-MultipleOf2019.mdx
+11-11
Original file line number
Diff line number
Diff line change
@@ -18,30 +18,30 @@ $$[1234, 234, 34, 4, 0]$$
18
18
19
19
**Keep in mind, that an empty suffix with is also considered.**
20
20
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$$.
22
22
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$$.
24
24
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).
26
26
27
27
However, we would still need to go through every pair of possible suffixes $(i, j)$ which would be $\mathcal{O}(N^2)$.
28
28
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.**
30
30
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$$).
32
32
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}$$.
34
34
35
35
So in our example with $$1234$$, our new array would look like this:
36
36
37
37
$$[2, 3, 0]$$
38
38
39
-
Where each index represents the count of a certain remainder.
39
+
Where each index represents the count of a certain remainder.
40
40
* There are $$2$$ suffixes with a remainder of $$0$$ when dividing by $$3$$, $$[234, 0]$$
41
41
* There are $$3$$ suffixes with a remainder of $$1$$ when dividing by $$3$$, $$[1234, 34, 4]$$
42
42
* And there are no suffixes with a remainder of $$2$$
43
43
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$$
45
45
46
46
If $$N<K$$, it should be $$0$$, since there aren't enough suffixes that can make a pair.
Copy file name to clipboardexpand all lines: solutions/silver/ceoi-12-JobScheduling.mdx
+2-2
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,9 @@ author: Chuyang Wang
9
9
10
10
## Explanation
11
11
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.
13
13
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.
Copy file name to clipboardexpand all lines: solutions/silver/cf-1359C.mdx
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ author: Jesse Choe
12
12
13
13
Consider the following observations:
14
14
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.
16
16
- 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$.
17
17
- 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.
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
12
12
time should be dropped first.
13
13
14
14
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
0 commit comments