Hi all,
The second contest of the 2019-2020 USACO season will be running from January 17th to January 20th. Good luck to everyone! Please wait until the contest is over for everyone before discussing problems here.
Edit 1: The contest is now live! Please do not spoil anything about the contest publicly until the contest is over for everyone, and please report any issues with the contest directly to the contest administrator via the instructions instead of posting them here.
Edit 2: Due to a configuration error, the contest is running for 12 more hours than originally stated. The contest window is still open, please wait for the window to expire at 4:00 AM UTC on January 22nd before discussing.
Edit 3: Results can be found here.
we should start preparing the contest lol
Technocup: Netflix adaptation
For all others who cannot joke about the USACO contests ( yet:) )
Quality mock contests for all levels of USACO: https://starleague.us/lms
These problems are way easier than the actual USACO. Last year I got full score on the mock Gold contest but I only got 300 in the actual contest.
I mean, that doesn't mean that the quality of problems is bad. Also in general I find it helpful to mock things that are one level higher than what I am currently in (e.g. Plat if I'm in Gold currently).
I am not sure if the contest is over but how to solve second problem from platinum?
While the contest should technically be closed (it is past 4:00 am in UTC-12 time), the page for the contest is still open (this might be due to an issue on part of the contest organizers), so it is safer to not yet discuss.
Yeah, please refrain from discussing until 11:00 pm eastern time (12 hours later than normal).
is silver cutoff gonna be like 600? everyone says it was super hard lol
discussion is not allowed yet, just wait for until the time Benq mentioned above to discuss
fishy15 cm :)
I believe the contest has ended, can anybody confirm?
It is now officially over.
Does anyone know how to solve the second gold problem, my solution was n^2 but got MLE.
Notice that you can create a tree structure from the cells. Iterate from the bottom layer to the top and merge subtrees into new subtrees. We can use a simple DP to find the answer.
We can create a matrix for the DP transitions. We just need to precompute prefix products and prefix inverse products to answer range queries.
300iq explained the solution to me so credits to him
orz
Basically we use the matrix solution but notice that since the matrices are sparse, we can do multiplication in O(k^2). Then, we can precompute prefix sums of the matrices to answer queries in O(k).
For P3 I have a bad solution which fortunately passes due to low constraints.
Screencast
Gold P3 is Balkan 2011 Trapezoid I think. Maybe that's why P1 is named "Time is Mooney"
Anyway, very short spoilers:
Basically, given some dependency between nodes, we have to count the subset of nodes that do not have depending nodes outside of the set. If we compress SCC, we can see that the DAG is a directed rooted tree. If we have that tree than counting is a simple DP. Constructing that directed rooted tree can be done by maintaining connected components for a suffix of rows, using disjoint sets. Idk if there is a simpler way to do this.
code
Divide and conquer gives $$$O((Q + N\log N) K^2)$$$. See code for details. imeimi told me that $$$O((Q+N)K^2)$$$ is possible too. It is same as what tmwilliamlin168 described.
code
We model the fall as a line $$$y = A_i - x \times i$$$.
$$$O(n^2)$$$: Observe that the path is always like $$$i \rightarrow Q_i$$$ or $$$i \rightarrow j \rightarrow Q_i$$$. So just enumerate all $$$j$$$.
$$$O(n\log n)$$$: Solve for all $$$i$$$ with $$$A_i < A_{Q_i}$$$. Possible $$$j$$$ satisfies $$$A_j < A_i$$$. So we have to find $$$j$$$ that has the smallest intersection with $$$Q_i$$$. Sweep in increasing order of $$$A_i$$$. Maintain a downward convex hull of lines. Then you can find it with a binary search (but linear search also works lmao). Case of $$$A_i > A_{Q_i}$$$ can be done similarly.
code
My method for plat 1 was slightly different:
For each contiguous segment on a row, merge them to form 1 node, and draw directed edges to nodes in the row below if they are connected.
We maintain a disjoint set data structure that keeps track of the groups of segments that, if the any of the segments in the highest row processed so far is flooded, will flood all of the segments. This disjoint set data structure also stores the number of ways to flood this group of segments. At first, all segments are a different group and the number of ways for each group is considered to be 1 (empty).
We then process row by row from the bottom. When we process a segment, we merge that segment with the groups that are connected to it via the directed edges. When this segment is empty, those groups below that are disjoint do not affect each other, so we can simply multiply the number of ways for each group together when we merge.
Once the merges are done for all segments in a row, each group now has the possibility of being entirely flooded by any of the segments in the top row. Thus, we add 1 to each of the groups that have a segment in this row.
At the end, we still have a number of disjoint groups, so we multiply the number of ways to flood each one together to get the final answer
Did not realize the equivalence of Gold P3 and Trapezoids. :| Admittedly, it didn't seem particularly original.
For Plat 2 my $$$O(nk^2+qk^2\log n)$$$ solution with segment tree passes $$$q=10^5$$$, not sure whether you can pass $$$q=2\cdot 10^5$$$ with this?
For Plat 3 we added some cases with large hulls which made one of our $$$O(n^2)$$$ solutions TLE, but apparently this didn't suffice.
Solutions
Thank you for the solutions!
Where can I see the all questions before the results come out (when would that be, though?), given the contest has now ended ?
all the problems can be found on the USACO discord server invite link
http://usaco.org/index.php?page=jan20results
Solutions and results are available.
For Silver Wormholes, I thought of using DSU ( Union Find ). Sort all edges in decreasing order of weights, and then after connecting each edge in this order, check if now all cows can sort themselves. So, I thought, let's view given array as permutation. Then we consider the index $$$i$$$ as value $$$i+n$$$. And then check whether each $$$i$$$ can reach $$$i+n$$$, but this is obviously TLE. How to do it faster? I have this feeling that there is a much easier approach.
My code.
https://github.com/bqi343/USACO/blob/master/Contests/USACO%20Solutions/2019-20/Jan/Silver/wormsort_merging.cpp
So, please correct me if I'm wrong. Instead of checking everything, in my code, if I checked each node in the smaller of the components while uniting, then similiar to the argument of merging sets in $$$O(nlogn)$$$ time, we have each element being checked only $$$logn$$$ times. Is that what I should have done?
yes
Okay, thanks a lot!
For Silver problem "loan", does anyone have a proof for the correctness of binary search solution?
I had to do a lot of math to prove it. Did I miss anything?
What's wrong with the analysis? (aside from the "mlik" typo, I don't think anyone proofread this >:( )
I think it can be rather difficult to prove the correctness of binary search. It's easy to guess but hard to prove.
Oops, I misunderstood. Suppose that $$$X_1<X_2.$$$ Isn't it easy to show that if $$$A\le B$$$, then $$$A-\max\left(M,\lfloor \frac{A}{X_1}\rfloor\right)\le B-\max(M,\lfloor \frac{B}{X_2}\rfloor)$$$ since $$$f(x)=x-\max(M,\lfloor \frac{x}{X_1}\rfloor)$$$ is monotonically increasing with $$$x$$$?
Oh, I didn't notice that monotonicity. I tried to prove $$$LHS - RHS \leq 0$$$ and break it into several cases because of $$$\max$$$ and $$$ \operatorname{floor}$$$ function. That needs lots of work. Thanks!
Can someone explain the maxmatch concept in the official USACO solution for the Silver loans problem? (line 11 onward in Nick's code)
You can verify (with a bit of math) that $$$\lfloor \frac{N-G}{X}\rfloor=Y$$$ remains the same after $$$t=\lfloor\frac{N-G-XY}{Y}\rfloor$$$ days (meaning that we subtract $$$Y$$$ from $$$N$$$ exactly $$$t+1$$$ times). After subtracting $$$t+1$$$ times, then $$$N-G<XY$$$, so $$$\lfloor \frac{N-G}{X}\rfloor$$$ has changed.