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

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

Hello everyone!

I want to invite you to participate in March Clash at HackerEarth. Contest is scheduled on March, 26. Contest duration is 24 hours, so there should be some comfortable time for every timezone :)

There will be six tasks in a problemset. Five of them are standard algorithmic problems with partial solutions allowed — you get points for every test that your solution passed. And the last task is an approximate problem — your score for this task depends on how good your solution is comparing to current best solution.

PrinceOfPersia is author of this problemset. You may check some of his previous contests to ensure that he's always providing contestants with interesting tasks :)

I was working on this contest as a tester, and I enjoyed solving given problems a lot :) I hope that several tasks will be not too hard for beginners (don't give up and show your best with partial scoring — even very naive solution may give you some decent points; and 24 hours should be enough for you to read all problems and find some tasks which you can solve) while some tasks are challenging enough to make this contest interesting for more experienced contestants. Even if you think that classic part of problemset is easy — go on, try to beat other contestants on approximate problem :) shef_2318 worked on this contest as translator — you will be provided with problem statements in English and Russian. Also I want to thank belowthebelt for handling all technical aspects of contest preparation.

As usual, here is one more reason for you to participate in this contest:

Top5 of leaderboard will also receive some nice prizes:

  1. $100 Amazon gift card + HackerEarth T-shirt
  2. $80 Amazon gift card + HackerEarth T-shirt
  3. $50 Amazon gift card + HackerEarth T-shirt
  4. HackerEarth T-shirt
  5. HackerEarth T-shirt

Good luck to everybody — I hope to see you at the scoreboard :)

Upd. Contest has ended :) Thanks to everyone for participating :) Congratulations to winners:

1) Carsten Eilks

2) ffao

3) LayCurse

4) pavel.savchenkov

5) mugurelionut

All solutions are available, also for all classic problems editorials and solutions by setter and tester have been published.

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

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

One hour to go for the contest. Good luck. :)

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

Did you consider to include sample explanations? That would help to make P4 more tolerable.

In the approximate problem, I think HackerEarth could have saved some considerable server spamming on my part if the generation method for the test cases was disclosed.

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

    I agree. Please don't use approximate problems where the test case generation method is not disclosed. It makes it almost impossible to test our solutions locally. This problem in particular had a large space of inputs and we were supposed to simply guess how the test cases were generated from such a large pool of possibilities? In particular, some approaches which worked really well on my local test cases made almost no difference or scored worse on the official test cases. In some of the recent Hackerearth contests this issue did not show up anymore, so I thought it was finally solved, but now it's back again. I guess it all depends on the experience of the problem setter, but I think the tester should also push for disclosing the test case generation method.

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

Can anyone explain the solution to P2 (The Great KL)?

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

    Sqrt decomposition.

    • For big groups  > sqrt(N).

    Use standard algorithm (2 DFSs) for finding perimeter of a tree in O(N).

    • For small groups  < sqrt(N)

    Choose a root, compute levels and ladders, Then check the distance of each pair in so the total complexity would be , where ni is the size of this group. (You can also use Tarjan LCA to avoid extra log)

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

      Ah nice, I thought it was going to be some complicated algorithm. So the solution runs in .

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

        In fact when we use the threshold for big/small to be it is which is better. But still when we use Tarjan for LCA it is plain .

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

      Not necessary. Consider this: We have a tree and some vertices are red and others are blue. We know the two endpoints of a longest path between any two red vertices. We paint a blue vertex with red color and we want to update this longest path.

      Lemma: One of pathes between these three vertices (endpoints of previous longest path and new vertex) is a longest path now.

      Converting the original problem to this trick is easy.

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

    NlogN solution.
    For each color keep track of the 2 farthest nodes and whenever u find a node whose distance to one of the 2 farthest nodes of that color is more than the distance between those 2 nodes , update the farthest pair of nodes for that color.
    Code

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

    I solved it with centroid decomposition.

    There are two cases:

    1. If the diameter pass through the centroid, then we only need the deepest node of every color in each of the branchs

    2. Otherwise, calculate recursively for each of the subtrees that are hanging on the centroid

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

Can anyone explain the solution of 3. problem?

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

    Suppose that we fix some subset of f's, say fs1, fs2, ..., fsk, and we want to choose some permutation p such that all a[i] + p[i] belongs to {s1, s2, ..., sk}.

    In other words p[i] can be equal j iff .

    It is a matching problem, between the domain of p and its counterdomain. Say D = {0, 1, ..., n - 1} and C = {0, 1, ..., n - 1}, and the edge between i and j exists iff p[i] can be equal to j.

    Now let us go back to the original problem. We sort f, say fs1 ≤ fs2 ≤ ... and for k = 1, 2, ... we check if we can find a permutation p for the subset {fs1, fs2, ..., fsk}. If so then the answer to the original problem is fsk.

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

    Binary Search on answer
    We want to check an answer <= 'X' is possible or not.
    Lets make a bipartite graphs with 'N' nodes from [0 , n — 1] on each side.
    Now the weight of edge from i on left side to j on right side will be f[i + a[j]]. if this weight is less than 'X' then add this edge to list of edges.
    Now find maximum bipartite matching.
    If matching == 'N' then return true else return false.
    Code

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

Solution to P4 (the great cyrus) ?

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

    Consider that we had to remove edges instead of Nodes. In that case it is a standard problem of finding the min-cut which is equal to the Max-Flow.
    Now we need to remove nodes instead of edges , so we keep 2 copies of each node say V1 and V2. Now for every edge (U -> V) in input , add edges in our graph from U2 to V1 and since its undirected , edge from V2 to U1 as well , give it weight infinity. And then for all nodes from 1 to N , add an edge from V1 to V2 with weight = the cost of removing that node. And then just find the maxflow from A1 to B2. Code

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

How I could know my approximation problem results in upsolving? Found bug five minutes after the end of the contest, and want to know how much it cost for me.

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

    +1. It seems that once the contest ends, the scores for the approximation problem are not shown anymore (neither for old submissions, nor for new ones). You only get if the solution was Accepted on each test case or not, but not the score which measures the quality of the solution on each test case (which is the most important thing).

    @organizers: Can you please fix this issue with the approximation problem? It's really annoying (both for upsolving and for looking at the best submissions of the other competitors).