Reminder: in case of any technical issues, you can use the lightweight website m1.codeforces.com, m2.codeforces.com, m3.codeforces.com. ×

### I_love_Tanya_Romanova's blog

By I_love_Tanya_Romanova, 4 years ago, ,

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.

amd 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:

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

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

• +63

 » 4 years ago, # |   0 One hour to go for the contest. Good luck. :)
 » 4 years ago, # |   +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.
•  » » 4 years ago, # ^ |   +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.
 » 4 years ago, # |   0 Can anyone explain the solution to P2 (The Great KL)?
•  » » 4 years ago, # ^ | ← 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)
•  » » » 4 years ago, # ^ |   0 Ah nice, I thought it was going to be some complicated algorithm. So the solution runs in .
•  » » » » 4 years ago, # ^ | ← 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 .
•  » » » 4 years ago, # ^ |   +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.
•  » » 4 years ago, # ^ |   +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
•  » » 4 years ago, # ^ |   0 I solved it with centroid decomposition.There are two cases: If the diameter pass through the centroid, then we only need the deepest node of every color in each of the branchs Otherwise, calculate recursively for each of the subtrees that are hanging on the centroid
 » 4 years ago, # |   +5 Can anyone explain the solution of 3. problem?
•  » » 4 years ago, # ^ |   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.
•  » » 4 years ago, # ^ |   +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
•  » » » 4 years ago, # ^ |   0 That is...
 » 4 years ago, # |   0 Solution to P4 (the great cyrus) ?
•  » » 4 years ago, # ^ | ← 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
•  » » » 4 years ago, # ^ |   +8 Dude, slow down. The main idea was inside the min-cut part. What should be the cost to remove an edge?
•  » » » » 4 years ago, # ^ |   0 I used ai * X + bi where X is a big number. However I got only 91.2 points :(
•  » » » » » 4 years ago, # ^ |   +3 Maybe your X was too big or not big enough.
 » 4 years ago, # |   +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.
•  » » 4 years ago, # ^ |   +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).