Solution of Codeforces Round #831 (Div. 1 + Div. 2) || Tutorial of Codeforces Round #831 (Div. 1 + Div. 2)
- Get link
- X
- Other Apps
Solution of Codeforces Round #831 (Div. 1 + Div. 2) || Tutorial of Codeforces Round #831 (Div. 1 + Div. 2)
Codeforces Round #831 (Div. 1 + Div. 2, based on COMPFEST 14 Final) Editorial
1740A. Factorise N+M
1740A - Factorise N+M
There are multiple solutions for this problem. We will discuss two of them.
One solution is to choose
Another solution is to choose
Time complexity for each test case:
1740B. Jumbo Extra Cheese 2
Author: Pyqe
Developer: errorgorn, Pyqe
1740B - Jumbo Extra Cheese 2
Consider arranging the rectangles such that the
Notice that if we sort the rectangles based on
We need to find an orientation configuration that results in the minimum value of
Therefore, the solution is to orient the rectangles to satisfy
Time complexity for each test case:
1740C. Bricks and Bags
1740C - Bricks and Bags
Firstly, sort
Let
p1<p2<p3 p1>p2>p3 p2<min(p1,p3) andmin(p1,p3)=p2+1 p2>max(p1,p3) andmax(p1,p3)=p2−1
In fact, Pak Chanek is always able to force it such that the bricks taken by Bu Dengklek form any configuration of
To maximise the final score, we can see that it is always more optimal to either use the third or the fourth case for
Therefore, the maximum final score is the maximum of these two cases:
(ai−ai−1)+(ai−a1) with3≤i≤n .(ai+1−ai)+(an−ai) with1≤i≤n−2 .
Time complexity for each test case:
1740D. Knowledge Cards
Author: Nyse
Developer: steven.novaryo
1740D - Knowledge Cards
Let card
The key observation for this problem is that, under given constraints, if we ignore cells
Therefore we can iterate the card in the stack
The active cards can be moved around freely if and only if there is at least one empty cell in the grid if we ignore
Time complexity for each test case:
1740E. Hanging Hearts
Author: Pyqe
Developer: Zappeko
1740E - Hanging Hearts
We define card
Let
In the optimal configuration, the elements of the longest non-decreasing subsequence in
- It consists of several sequences of cards in the form of
[v1,v2,…,vk] such thatpvi=vi+1 for all1≤i<k . - For any pair of cards from two different sequences, one must not be dangling onto the other.
We will use dynamic programming on tree. Let
- If card
i is used in the longest non-decreasing subsequence, then the maximum answer is the maximum value ofdist(j,i) for allj∈Di . - If card
i is not used in the longest non-decreasing subsequence, then the maximum answer is the sum ofdp values of all cardsj directly hanging ontoi (i.e.pj=i ).
Time complexity:
1740F. Conditional Mix
Author: Pyqe
Developer: errorgorn
1740F - Conditional Mix
Let
We can obtain that a multiset
We proceed with formulating a dynamic programming solution. Let
We can cut down the number of states by noting that
Time complexity:
1740G. Dangerous Laser Power
1740G - Dangerous Laser Power
Claim: There is a construction where all portals are good.
We will proceed with the construction.
The key observation of the problem is that for a portal
Let's say we already have the type settings of all lasers. Consider all possible lasers that at some point enters a certain face of portal
Consider the first portal in that backtracking path that has a strength greater than or equal to
Using the observation above, we can see that we must only backtrack until we find a portal with a strength greater than or equal to
Therefore, the construction can be generated by calculating the type settings of the portals from the smallest to the largest strengths. In each iteration, we use the type settings of the previous portals to find the backtracking paths of the current portal. If we already know the
The naive implementation of this has a time complexity of
Time complexity:
1740H. MEX Tree Manipulation
Author: steven.novaryo
Developer: steven.novaryo, Pyqe
1740H - MEX Tree Manipulation
Define
Let's solve a simpler problem. Imagine that you are given an array
Let
- If the input is not
x , then the output isy . - If the input is
x , then the output isz .
This means the relationship between the new element to be appended to
Define the heavy child of vertex
Let
Let's consider a path in the tree that traverses through parents while only using heavy edges. Consider the relationship between the value of the vertex at the beginning of the path and the end of the path. Let's calculate the
Let's decompose the tree into chains of heavy edges. For each chain, construct a segment tree with each node in the segment tree calculating the relationship triple
Suppose we want to add a new vertex. The vertices that have their values changed are the ones that lie on the path from the new vertex to the root. Observe that that path only traverses through at most
To get the sum of the values of the entire tree after an operation, we can store two new variables in each node of the segment tree of each chain that represents the sum of the chain segment for the two possible cases of the input.
Time complexity:
1740I. Arranging Crystal Balls
Author: NeoZap
Developer: errorgorn, Pyqe
1740I - Arranging Crystal Balls
Let's simplify the problem such that the only possible operation for each
To solve this, we first define
In order to extend to the original problem, we can see that for a given array
We can see that
Define
For the
Let's consider the connected component
After this, we must the minimum value of
Consider the contribution of a single element
- It adds
(x−w)modm to all values offi(x) for eachx going up modularly fromw to(w+⌊m2⌋)modm - It adds
(w−x)modm to all values offi(x) for eachx going up modularly from(w+⌈m2⌉)modm tow .
We can see it as "changing slope" at most three times, namely in
This means, if we add up all contributions of each element, the number of points the slope changes in one connected component is at most
Consider an array
This means, we can always do that operation to get an array
We can solve this using divide and conquer. We first call the recursive function
The depth of the recursion is at most
Time complexity:
- Get link
- X
- Other Apps
Comments
Post a Comment