Note: I can't figure out how to place the tutorials inside spoilers. If someone is familiar with how CF spoilers work and can help I would really appreciate it. For now, be warned that the tutorials are visible by default (but everything else isn't)
Thanks for participating in our contest!
1509A - Average Height
Author: Kuroni
First solve: Nutella3001 at 00:01:02
Hint How can you write the condition that $$$\frac{a_u + a_v}{2}$$$ is an integer in a more useful way? Think of the parities.
Tutorial is loading...
Comments from the authors 1509B - TMT Document
Author: Ari
First solve: blue at 00:04:51
Hint You can think of the partition as associating to each $$$M$$$ character a $$$T$$$ to its left and a $$$T$$$ to its right. What's the best way to perform this assignment?
Answer Assign greedily from left to right.
Tutorial is loading...
1509C - The Sports Festival
Author: Ari
First solve: vrobert at 00:05:48
Hint 1 What is the discrepancy of the last stage? How can we make it smaller in previous stages?
Answer The discrepancy of the last stage is always the difference between the largest and the smallest $$$a_i$$$. We can make it smaller in the previous stages by placing the smallest or the largest $$$a_i$$$ at the end.
Hint 2 Use dynamic programming.
Tutorial is loading...
Comments from the authors This problem was originally going to appear in
Codeforces Round 668 (Div. 2), but it was removed one day before the contest for balance reasons :P
1508A - Binary Literature
Author: Ari
First solve (Div. 2): traxex2 at 00:22:48
First solve (Div. 1): tourist at 00:05:04
Hint 1 Consider two of the strings. We can obviously achieve our goal using at most $$$4n$$$ characters. How can we save some of them?
Answer Take advantage of any common subsequence in our two strings by including the characters in it only once.
Hint 2 Find a long common subsequence that has a simple structure. You'll need to involve the third string as well.
Hint 3 Either $$$00\dots 0$$$ or $$$11\dots 1$$$ is a subsequence of each string.
Tutorial is loading...
Comments from the authors This problem was originally suggested as a 2B. It turned out to be too hard and was switched to 2C, before being further switched to 1A because it was still too hard. Some testers still believed this problem to be even harder, but we ended up deciding to have it as 1A with a larger score than usual.
Apologies to the testers who had to solve this as if it was the second easiest problem in the contest :^)
1508B - Almost Sorted
Author: Both of us!
First solve (Div. 2): shenmadongdong.qaq at 00:29:52
First solve (Div. 1): tourist at 00:08:19
Hint 1 What is the general structure of an almost sorted permutation?
Answer Start with the identity permutation, choose some disjoint subarrays, and reverse each of them.
Hint 2 How many almost sorted permutations of length $$$n$$$ exist? In other words, how many ways are there to reverse subarrays?
Hint 3 Two options — either solve recursively in a greedy fashion or find a smart bijection.
Tutorial is loading...
Comments from the authors This problem's creation has a funny story. Back when we were coming up with problems for Round 668, I (Ari) came up the following relatively simple and standard problem and shared it.
The next day, Kuroni saw the problem, but misread it and ended up solving the version that made it into this contest, which we think is a lot cooler!
One more fun fact for your consideration: This problem's name in Polygon is "sorrow".
1508C - Complete the MST
Author: Kuroni
First solve (Div. 2): deepspacewaifu at 01:42:36
First solve (Div. 1): maroonrk at 00:33:17
Hint 1 How can we solve this problem without the restriction that the xor of all edge weights is $$$0$$$?
Answer Just assign $$$0$$$ to every unassigned edge :P
Hint 2 When does the solution to the unrestricted problem fail for the real problem?
Answer When any minimum spanning tree (of the graph with every unassigned edge having weight $$$0$$$) contains every unassigned edge, and the xor sum of all the edge weights is not $$$0$$$.
Hint 3 Leave the xor sum of the weights of the unassigned edges in the spanning tree fixed. How do we minimize their sum?
Answer Assign the entire xor sum to a single edge, and assign weight $$$0$$$ to every other edge.
Hint 4 Exactly one unassigned edge ends up with a non-zero weight. If we don't use all unassigned edges, which others can we use?
Answer Any edge that isn't part of the MST when we consider unassigned edges to have weight $$$0$$$, and that doesn't form a cycle with pre-assigned edges with smaller weights.
Tutorial is loading...
Comments from the authors If the unassigned edges in the graph don't form a forest, then the answer is simply the weight of the MST where all the unassigned edges have weight $$$0$$$. Thus the interesting tests in this problem require these edges to form a forest, which means $$$m \ge \frac{n(n - 1)}{2} - (n - 1)$$$. This automatically limits the maximum value of $$$n$$$ to approximately $$$2\sqrt{m}$$$. Concretely, $$$n \le 633$$$ for all interesting tests in this problem. You can also use this to obtain a solution that runs in $$$O(m \sqrt{m})$$$, which a tester found, and which passes if implemented reasonably.
1508D - Swap Pass
Author: Ari
First solve: ksun48 at 00:57:13
Hint 1 It is always possible to find the sequence.
Hint 2 There's a simple algorithm that fixes a point and repeatedly moves its current label to the correct position. When does it work?
Answer When the permutation of the labels is a single cycle.
Hint 3 Any permutation can be split into one or more cycles. What can we do to these cycles?
Answer Merge them, by swapping two elements in different cycles.
Hint 4 We would like to merge all cycles of the permutation by swapping elements in different cycles and then repeatedly move each label from a certain point to its correct location. How can we do this without intersections?
Answer Fix a point beforehand to perform the final step, and sort angularly with respect to this point.
Tutorial is loading...
Comments from the authors This problem was originally proposed with the points always being the vertices of a convex polygon. This allows us to do a slightly different solution where we first merge the cycles and choose the pivot afterwards by choosing a point unaffected by the previous swaps.
The reason for having $$$n = 2000$$$ in this problem rather than a larger $$$n$$$ like $$$10^5$$$ is because of the validator: it is essential to not have three collinear points in this problem, and I don't know how to check this for large $$$n$$$. The small $$$n$$$ also makes the checker much easier to write, though it's possible (albeit tricky) to write a checker that works in $$$O(n \log n)$$$.
Regarding the number of operations used: The solution described in the editorial uses approximately $$$\frac{3}{2}n$$$ operations in the worst case when the permutation consists of cycles of size $$$2$$$. The minimum number of operations is lower bounded by $$$n - 1$$$ by combinatorics reasons when the permutation is a single cycle. Moreover, by Euler's formula, we have an upper bound of $$$3n - 6$$$ operations for any valid sequence, which goes down to $$$2n - 3$$$ when the points are the vertices of a convex polygon. I don't know of a solution that uses $$$cn$$$ operations for some $$$c < 3/2$$$, nor do I know of a general test case where it can be proven that at least $$$cn$$$ operations are needed for some $$$c > 1$$$, so I'd be really interested in seeing either.
1508E - Tree Calendar
Author: Kuroni
First solve: ecnerwala at 01:02:26
Hint 1 During the process, we will repeatedly push the same label down until we no longer can. What happens at this point?
Answer The labels that have been fully pushed down will look like a post-order of the tree, while the other labels will look like a pre-order of the tree.
Hint 2 Look at the children of a particular vertex. What can we say about the ones that are fully pushed down in relation to the ones that aren't?
Answer Every fully pushed down label is smaller than every other label.
Hint 3 For each node, the order of the labels of its children stays fixed.
Hint 4 How can we use the previous observations to identify the state of the process?
Answer We can reconstruct the DFS order and the fully pushed down labels. Then check that the current pushing step of the process is valid.
Tutorial is loading...
Comments from the authors This problem was inspired by a wrong solution to
1477D - Nezzar and Hidden Permutations, but it seems that knowing that problem beforehand doesn't help at all to solve this one.
1508F - Optimal Encoding
Author: Kuroni
First solve: ecnerwala at 01:52:02 (The only contestant who solved this problem!)
Hint 1 Start by solving the problem for $$$q$$$-encodings only.
Hint 2 We can get an encoding by including every possible edge. Which of them can we exclude?
Answer We need to keep an edge $$$u \to v$$$ if and only if no other path from $$$u$$$ to $$$v$$$ exists.
Hint 3 What does the previous observation look like from the perspective of a single vertex?
Answer Each vertex has at most two outgoing edges, one on each side, and we can easily characterize when one of them is redundant.
Hint 4 We need to solve the full version now. For a vertex $$$u$$$, how do the endpoints of its outgoing edges change when we add a new interval?
Answer The endpoints of the right edges increase monotonically, while the endpoints of the left edges decrease monotonically.
Hint 5 How can we use the previous observation to characterize edges becoming redundant more concretely?
Answer For each right edge, we can find a particular left edge, such that the right edge becomes redundant once the left edge appears. This gives us an interval of times for each edge during which it is relevant.
Hint 6 Use Mo's algorithm on the input intervals to find the relevant edges.
Tutorial is loading...
Comments from the authors Huge shoutouts to
tfg who came up with one of the key steps of the solution! Including this problem probably would have not been possible without him. ❤️
Finally, here's some funny moments that happened while we were working on the round :)