Блог пользователя xiaowuc1

Автор xiaowuc1, 5 лет назад, По-английски

Hi all,

The second contest of the 2020-2021 USACO season will be running from January 22nd to January 25th this weekend. 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.

  • Проголосовать: нравится
  • +154
  • Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +29 Проголосовать: не нравится

The first contest of the 2020-2021 USACO

There is a typo first -> second.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Hoping to make Gold. Do you think someone with my rating graph has a decent chance at making Gold?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How do I register and participate? I opened the Contests page but there are only previous contests there.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Is there a way to see the standings? I am completely new to the USACO platform. Thank you.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится -98 Проголосовать: не нравится

Solve all the silver using 3hours and 56 minutes.....

Think the problem for a lot of time, good problem!

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

When can we discuss?

»
5 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +49 Проголосовать: не нравится

Here are my solutions to all of the gold problems:

Problem 1: Uddered But Not Herd
Problem 2: Telephone
Problem 3: Dance Mooves

Side Note: Was it intentional to make it hard to notice that there are $$$\leq 20$$$ distinct characters in the string in problem 1?

Also: Does anyone know the solution for Plat Problem 3? I implemented Offline Dynamic Connectivity, but it had a complexity of $$$q*n*log(q)*log^2(n)$$$ with a bad constant, so it was too slow.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +47 Проголосовать: не нравится

    I agree, spent about 30 minutes thinking that there are <=26 characters instead and tried to find a polynomial solution because I thought <= 20 was a subtask. I wish they had stated that clearly in the problem statement, not just in the subtask list...

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится -16 Проголосовать: не нравится

    Hii!!!!

    Was it intentional to make it hard to notice that there are ≤20 distinct characters in the string in problem 1?

    Are you sure ??????????... Because i solved it for 2 hours with this very obvious $$$n^{2}*2^{n}$$$ solution which is a kind of repeat to this problem https://mirror.codeforces.com/problemset/problem/1238/E

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится -11 Проголосовать: не нравится

    Wait a minute!! I just went through the question and read it 10 times then i noticed the scoring portion. Are you talking about M i l d r e d ?? If yes, then its insane.

  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    For Problem 2, my friends qwerty190 osmium Freaksus got AC by doing Dijkstra, even there were n^2 edges. I am so confused why those solutions got passed.

    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +8 Проголосовать: не нравится

      Would they be comfortable sharing their code? Sometimes brute force approaches with things like pragmas and heuristics pass, which is unfortunate.

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится

        As far as I know, they don't use this kinda stuffs. I am contacting them, as soon as they reach me, they would reply to you in this comment!

        Edit: They didn't save their codes, so they can't get access to them right now. After this session's USACO problem page opens, they would get the codes. Moreover sorry for the misinformation, one of my friends got all ac by doing Dijkstra, but the other two got 12 test-cases out of 13.

    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +14 Проголосовать: не нравится

      Yeah, I also know some friends that passed with just a brute force (without any pragmas or the sort.) I hope USACO adds some tests and rejudges, because a naive N^2 dijkstra should not get 12 or 13 cases.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +28 Проголосовать: не нравится

    You can solve plat problem 3 in $$$O(NM + Q(N+M))$$$; essentially, you approximate the answer by counting how many CC's have their upper left corner inside the query rectangle using prefix sums, and then you walk around the perimeter of the query rectangle to fix your approximation. There are various strategies to handle the details of the counting/overcounting; the cleanest strategy I know is to consider the (planar) graph of lattice points and use the Euler characteristic formula V-E+F = # cc's + 1.

    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      How do you count the number of faces efficiently in this graph?

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +10 Проголосовать: не нравится

        Note that each face/cycle of the original graph is either fully contained within the query rectangle, or it merges with the "outside" face (that extends to infinity) and doesn't contribute to the count. Thus, we just need to count the number of original faces fully contained within the query rectangle. From now on, "faces" will refer to faces of the original, whole graph.

        First, number the faces, and for each lattice point (corner between 4 tiles), precompute which face it belongs to using flood-fill. Now, for each face, pick one lattice point in it as the "representative", and compute rectangular prefix sums for the number of representatives in a region. This is our approximation/overcount for the number of faces fully contained; it may include some extra faces whose representative point is inside the query, but are not fully contained. Fortunately, these faces must intersect the boundary of the query rectangle. Thus, walk along perimeter of the query region, and subtract off the number of faces which intersect the perimeter at least once and whose representative is inside the query region; we can count these in linear time with a boolean array or a hashset. Then, we will be left with exactly those faces which are fully included, so V-E+F will work.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    As ecnerwala said: the graph is planar, so we want to know the value of $$$V - E + C$$$, where $$$V$$$ stands for the number of vertices, $$$E$$$ for the number of edges and $$$C$$$ for the number of cycles. $$$V$$$ and $$$E$$$ can easy be calculated in constant time per query with prefix sums. To calculate general cycles we can just run DSU on the dual graph. Then for each connected component in dual graph we calculate its bounding box.

    So, we are given a list of rectangles (at most $$$n \cdot m$$$) and for each query we have to count how many of them are inside query's rectangle. It's easy to see that at this point complexity $$$O(q \cdot n \cdot m)$$$ is enough, as it's a very simple check.

    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +15 Проголосовать: не нравится

      Making strong tests is hard :(

      I think my original proposal had $$$Q \leq 5000$$$ and $$$N, M \leq 2000$$$ without the increased TL — do you think the $$$O(QNM)$$$ solution still would've passed with those constraints?

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +15 Проголосовать: не нравится

        Don't forget that you can count number of small bounding boxes (e.g. 1x1) insde of query in linear time, so this solution would have very small constant.

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +5 Проголосовать: не нравится

        Don't worry, it's not about the tests, just the limitations. As Andrew wrote it can be squeezed even more. I think that for all rectangles (assume there are $$$c$$$ of them and assume $$$n=m$$$) with fixed height and width limited by some $$$x$$$ we can solve the problem in $$$O(n^2 + c \cdot x + q)$$$, so we can solve rectangles with height and width small smaller than $$$\sqrt{n}$$$ in $$$O((n+q) \cdot n \cdot \sqrt{n})$$$. Then, there are at most $$$n \cdot \sqrt{n}$$$ rectangles, so the whole complexity would be like $$$O((n+q)^{5/3})$$$.

        Btw. there are always at most $$$20-30$$$ tests. Are they tests or are they really groups of tests?

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +5 Проголосовать: не нравится

        Uhoh... I wrote some weird bitset shit that gives $$$O(\frac{NMQ}{B} + Q 2^B)$$$ time complexity. I thought I got the intended solution and thought the problem was weird, but the model solution is actually nice.

        If you had $$$Q \le 5000$$$ then I might try to use the brain :) It doesn't look like tight limit at all.

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        I think tests are actually a bit weak. I managed to AC dynamic connectivity (written in part by 12tqian) solution with $$$N^2 log^2{N} + N^3/64$$$ in about 2.7/3 seconds. It's worth noting because it's in essence the "trivial" dynamic connectivity solution with relatively few constant optimizations.

  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    gold P2 can be solved with djikstra,you can reduce the number of edges to $$$O(nk)$$$ with the following observation :

    given node $$$v$$$ and the set of groups that is compatible with $$$v$$$,you only need to connect $$$v$$$ to two nodes in each such groups namely the node closest to $$$v$$$ from the right and closest to $$$v$$$ from the left

    the proof is as follows:

    assume you have a optimal path $$$A$$$ $$$\to$$$ $$$B$$$ $$$\to$$$ $$$C$$$ and that $$$B$$$ is neither the closest node to the right or left of $$$A$$$ (within the same group as $$$B$$$),then you can modify $$$B$$$ accordingly to be one of the two nodes described above with some casework

    the final step is to connect edges to $$$n$$$ whenever possible,each node atmost have $$$2k+1$$$ edges so there are atmost $$$2nk + n-1$$$ edges

  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Could you share the "minimum feedback arc set" dp solution on the topsort pls?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +66 Проголосовать: не нравится

There were problems initially with the output files of Gold P1. Spent 2 hours before rage quitting wondering why my '3' is not their '3'.

Really appreciate though that the issue was recognised and quickly resolved after I sent an email.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve Silver P1 ? Does it involve bitsets ?

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    It was the classic swapping graph-theory problem! See my code below if you're curious.

  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +2 Проголосовать: не нравится

    Consider the cycles in the final permutation produced after doing the $$$k$$$ moves. Each cycle is independent, and it can be shown that every node in the cycle has the same answer. The answer for some node in the cycle is the size of the union of the sets of all distinct locations each node in the cycle visited in the first $$$k$$$ moves (this is because each node in the cycle visits the locations of every node in the cycle). This value can be calculated in amortized linear time, as the sum of sizes of the sets is $$$\leq 2k$$$. The final complexity is $$$O(n+k)$$$.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +2 Проголосовать: не нравится

My USACO Silver solutions (finished with 15 minutes to spare, only)

Problem 1
Problem 2
Problem 3

Full Disclaimer: My solutions are somewhat messily written due to the time pressure.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +6 Проголосовать: не нравится

I will also share my solutions for the gold division. I’ve managed to get full credit on Problem 1, got 12/13 tests on Problem 2 (will talk about that when describing its solution), and 5/20 on Problem 3.

Problem 1
Problem 2

I won’t describe Problem 3, since I’ve only managed to solve the first Subtask. Overall, a pretty interesting and hard Gold Round. Def easier than December though (In December I’ve scored around 400 and now around 720). What do you think will be the score needed to promote?

EDIT: Regarding problem 2, I only care about the first and the last cow of each type, not about the first 2.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +13 Проголосовать: не нравится

    Can you share your code for problem 2? I want to try to break it, but I don't fully understand the solution. I can also stress test it (I have a generator and a correct solution already), and I'll tell you if I can find a counter test.

    As for the promotion cutoff, I would guess either a 700 or a 750. I'm probably biased here because I solved all of the problems (and I'm good at graph problems), but this contest didn't feel absurdly hard (unlike the last one). For reference, last contest I got a 200 on gold, but in this one I ICP'd and got a 450 on platinum. I think a 700 or a 750 cutoff would be reasonable, but we'll have to wait and see.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I'm pretty curious about the silver-->gold cutoff. I made it with a 1000, but since last contest I got only 350, I was thinking maybe I got lucky and it was just an easy contest. Did you guys think it was an abnormally easy silver contest?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Is it intended to make P1 < P2 < P3 or is it rather random?

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    From the USACO Guide:

    Problem difficulties can be out of order, so keep that in mind before focusing down 3 hours on problem 1 and not getting anywhere. Do a good amount of thinking on each problem before deciding which ones to focus on and which to put aside. Historically, the first platinum problem has never been the hardest (though you shouldn't count on this).

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I actually found P1 the hardest, any hints on its solution?

    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Try to think about the shortest odd and even paths in every graph.

    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Waiting for hint/editorial for P1 platinum also.

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +5 Проголосовать: не нравится
        Solution for Plat P1
        • »
          »
          »
          »
          »
          5 лет назад, скрыть # ^ |
          Rev. 3  
          Проголосовать: нравится +20 Проголосовать: не нравится

          There is no need for a segment tree. Using the fact that

          $$$min(max(d[x][0]), max(d[x][1])) = max(d[x][0]) + max(d[x][1]) - max(max(d[x][0], d[x][1]))$$$

          helps a lot. Infinity contributes 0 to the answer.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve Platinum P2 and P3?

  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +5 Проголосовать: не нравится
    Solution to Plat P2

    For P3, ecnerwala described a solution in a comment above.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +33 Проголосовать: не нравится

    I wrote about P3 above. P2 is a history exam about problem "Icy Roads" from Gennady Korotkevich contest 1 from 2013.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +11 Проголосовать: не нравится
    P2 intuitive solution w/o knowing some obscure contest
    • »
      »
      »
      5 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +5 Проголосовать: не нравится

      A general summary of the technique is to consider the values of the "naive DP" as a function in one of the state variables, and try to identify/prove if it's convex; if so, try to maintain it or its derivative as piecewise linear or quadratic. (Depending on the problem, you may want to store inflection points or segments or something else.)

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

sorry to comment something during the contest. (got so many downvotes...)

This is my first time to do usaco contest brozon & silver.

I spend nearly one hour to figure out the simple dp solution for the 3rd problem, and another one hour to transfrom the second question to a well known question.

For the second, get L[i], r[i] be the first smaller position from left and right of i-th number, then answer is about distinct elements in range. This is a well known problem called D-query in spoj.

For the third, consider by row, thus two rows will be the same or complete different. We can do it using dp[N][2]. Then swap the element by main diagonal, do the dp again.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +37 Проголосовать: не нравится

When will the results post?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For Gold problem 2, if you're currently at cow A and are looking to travel to a cow of breed B, is it correct that you only have to check the cows in B closest to A in either direction and the rightmost cow of B? Because (I think) the only time it's optimal to go all the way right is if you can get to cow N. Otherwise, let's say that the next cow you want to travel to is cow C, the cow from breed B closest to A on the left L, and the cow from B closest to A on the right R. Since the answer can be represented as (N-1) + 2 * (backwards distance traveled), the goal is to minimize the total backwards distance traveled. If C is left of L, then no matter what you'll have to travel at least A-C distance to get there, so one of your best paths are guaranteed to be A -> L -> C. If C is right of L and left of R, then at least one of the optimal paths are A -> L -> C or A -> R -> C, whichever of the two travels backwards less. Otherwise, if C is right of R, then your one of your best paths are guaranteed to be A -> R -> C.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Results are out!

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

(int) m%k instead of (int) (m%k)

What a great way to miss an icp.