### dj3500's blog

By dj3500, history, 4 years ago,

Hello CodeForces! This year again, I'd like to invite you to the online mirror of an open championship of Switzerland called the Helvetic Coding Contest. A mirror was also held last year — see here: Helvetic Coding Contest 2016 online mirror (teams, unrated)

The Helvetic Coding Contest is a yearly contest held at the EPFL in Lausanne by the PolyProg association. The contest itself took place on April the 1st, but the online mirror is scheduled on Sunday, 28th of May, 11:05 Moscow time. The duration is 4:30.

Rules:

• you can participate in teams or individually (1-3 people),

• standard ACM-ICPC rules (no hacking),

• the contest is not rated,

• if you have participated in the onsite contest, please do not participate in the mirror.

You will help us find the cow Heidi and participate in some April-Fools-Day confusion. The contest will feature 5 series of 3 related tasks with increasing difficulty (easy/medium/hard). Sometimes it may be the case that a solution for the hard version solves all of them, but usually not. We think that the problemset is diverse and interesting, and while the contest is ACM-style, you will find that some problems are not so standard. Most easy&medium problems are even solvable in Python, so you can also recommend this contest to your newbie friends :)

Acknowledgments: the problems were set by Christian Kauth, boba5551, meret, DamianS and myself. Thanks also go out to people who helped with the statements and testing: maksay, Michalina Pacholska (who also draws the cows), Benjamin Schubert, Aleksa Stanković, Ruofan Zhou; Tatiana_S for Russian translations and KAN for CodeForces coordination, as well as everyone involved in the actual onsite contest, who are too many to name here. We also thank the sponsors Open Systems and AdNovum. Lastly, thanks to MikeMirzayanov for CodeForces and Polygon (which was used to prepare the problems).

Finally, in a bit of autopromotion, note that you can use Hightail to automatically test your solutions :) Good luck!

After-contest UPDATE:

## >>> Editorial <<<

Feel free to ask questions in this topic.

Thanks to everyone who participated! We hope you have enjoyed the problems. Congratulations to the winners:

1. ★SweeT DiscoverY★: dotorya, zigui, molamola. (solved all problems!)

2. japan-cookie: sigma425, sugim48, yosupo (solved all problems!)

3. HSE Bluebell: Um_nik, Kronecker

4. Veteran: I_love_Hoang_Yen, chemthan, ngfam_kongu

5. m(_ _)m: tmt514, Shik, dreamoon_love_AA

6. never red: xxTastyHypeBeast666xx, gongy, rnsiehemt

7. rng_58

8. (｀・ω・´): FizzyDavid, ohweonfire

The winners of the onsite contest (Petr Team) also solved all problems.

See you again next year!

• +105

 » 4 years ago, # |   +31 6 weeks ago xD
 » 4 years ago, # |   +35 Why am I not able to register as a team?
•  » » 4 years ago, # ^ |   +23 Good point, we'll fix that.
•  » » » 4 years ago, # ^ | ← Rev. 2 →   0 Team Registration is not fixed yet .[ UPD: Fixed Now ]
•  » » » » 4 years ago, # ^ |   +22 Seems to work now.
 » 4 years ago, # |   0 Broken timeanddate.com link in email: http://timeanddate.com/worldclock/fixedtime.html?day=28&month=5&year=2017&hour=11&min=5&sec=0&p1=166 While link in the post is: https://www.timeanddate.com/worldclock/fixedtime.html?msg=Helvetic+Coding+Contest+2017+online+mirror&iso=20170528T0805&ah=4&am=30 
 » 4 years ago, # |   +26 one computer per team?
•  » » 4 years ago, # ^ |   +26 No according to last year. http://codeforces.com/blog/entry/45628?#comment-304527
 » 4 years ago, # |   +3 Why am I getting "Can't unregister. Possible reason: You made at least one action in the contest."I want to be in a team with JustInCase and radoslav11 but it won't allow me to unregister :(
•  » » 4 years ago, # ^ |   0 For what it's worth, I cannot see you on the registrants list either...
 » 4 years ago, # |   0 How to solve L?
 » 4 years ago, # |   0 I wonder for who didn't learn about Poisson distribution, is it possible to solve D without Google?
•  » » 4 years ago, # ^ |   0 Yeah, we just played a bit with some constants and it passed.
•  » » 4 years ago, # ^ |   +44 All information you need (i.e. the distribution function) was written in the statement.Try all 2000 distributions (2 types, 1 <= P <= 1000). For each distribution compute the probability that you get the given sequence. Find the distribution that gives the maximum probability.
•  » » » 4 years ago, # ^ |   +5 This sounds so obvious (and elegant!) that I wondered why I didn't think of this. Then I realized that I have no idea how to calculate the probability and even your code didn't help with that. After reading the editorial, I see that I had to know some formula.I don't think that someone who has to google Poisson distribution would know more advanced things about statistical analysis, like the formula you used.
•  » » » » 4 years ago, # ^ |   +30 Fix a distribution D, and let D(k) be the probability that this distribution gives k. Let a1, ..., a250 be the input.We want to compute the product D(a1) * ... * D(a250), but this is too small. I computed log(D(a1)) + ... + log(D(a250)) instead.
•  » » » » » 4 years ago, # ^ |   +15 Thanks! That sounds both brilliant and dubious at the same time. I mean, if I came up with this by myself, I don't think I would convince myself that it's correct and there is no flaw.I don't know how to express my doubt, it just feels really weird to treat every input value separately. Of course I believe you and my math says it's correct but somehow my intuition still can't accept it.Is the G-Test described in the editorial equivalent to your measure? I always thought these tests were highly approximate and that there was no better way to test the statistics. Yet your way seems better and simpler. What am I missing?
•  » » » » » » 4 years ago, # ^ | ← Rev. 2 →   +5 Isn't this just maximum-likelihood estimation, essentially? Since the samples are drawn independently, the probability of the sample vector is the product of their individual probabilities. As rng_58 said, it is too small, so we take the logarithm. This is then called log-likelihood. Comes up all the time in statistics and in machine learning.This thing (MLE) gets even weirder when dealing with continuous distributions. There, the probability of having sampled any particular value (real number) is zero, but we take the probability density function at that value instead and it still somehow works... ;)
 » 4 years ago, # |   +3 What is fast solution for B?
•  » » 4 years ago, # ^ | ← Rev. 4 →   0 My solution went like this: find the next position of every book for every element of the array (or inf if that's the last time you need it). For every book you buy put it in a priority queue and once you go over k books, remove the book at the head of the queue.I figured it'd be optimal to remove the book that was furthest away from my current position because it'd be more important for me to keep the books that are needed earlier so that I don't have to repurchase. Edit: ran in like 300 ms with Java.
•  » » » 4 years ago, # ^ |   0 Thanks!
 » 4 years ago, # |   +20 For the last task, I assumed that the optimal solution for k + 1 is a superset of the optimal solution for k. Is this correct?
•  » » 4 years ago, # ^ |   +10 Yes (at least with 'an' optimal solution :) ).
•  » » 4 years ago, # ^ |   +10 You can model it as MCMF network (just for the sake of the proof, not actual implementation) and then this claim becomes obvious.
•  » » » 4 years ago, # ^ |   +10 Yes, this is actually described in the editorial. Some people prefer to think of this as a min-weight bipartite matching instance (and the Hungarian algorithm also builds matched-vertex-wise increasing solutions).
 » 4 years ago, # |   +15 The editorial link has been added to the first post.
 » 4 years ago, # |   +5 Auto comment: topic has been updated by dj3500 (previous revision, new revision, compare).
 » 4 years ago, # |   +10 How to solve last task with simple code? I implemented segtree with almost infinity integers...
•  » » 4 years ago, # ^ |   0 Great question! Maybe one of the two teams who have done so (never red 27411549, ★SweeT DiscoverY★ 27412140) could explain their solutions?
•  » » 4 years ago, # ^ |   0 Besides, congrats for squeezing this in the last minute :)
•  » » 4 years ago, # ^ | ← Rev. 5 →   +58 There is a neat way to remove constraints about K.Let's think about this problem first: "Choosing a_i and b_js with same constraints with original problem and minimize sum of those values, but there are no constraints about how many pairs we can choose."Let's assume that we are solving problem above with new A and B arrays, which are defined as following: a'_i = a_i + t, b'_i = b_i + t, (t is some constant value, which can be negative number)If t = INF, the best way will definitely be choosing no pairs. If t = -INF, the best way will be choosing all the pairs, (a'1, b'1), (a'2, b'2)... Furthermore, as t increases, the # of pairs we have to choose will decrease. So, if we choose some "good" t for the problem (using parametric search with t), the best way for that problem will be choosing exactly K pairs. At that point, we can simply get the answer of original problem by subtracting 2*t*K from modified problem.If we don't have constraints about K, the problem becomes much easier! We still have to use similar idea with editorial, (I'm not sure about this point. It was not me completing this solution in our team.) but code becomes a lot easier to implement.
•  » » » 4 years ago, # ^ |   +30 I used this trick for N, I binary search for t then use n^2 dp. Then I replaced it with a greedy algorithm to pass O. I don't know how to prove it though :(Basically, for each b, I either create a new matching with minimum a which is unmatched, or replace maximum b in an existing matching. Please let me know if anybody has a proof!
•  » » » » 4 years ago, # ^ | ← Rev. 5 →   +23 You probably already got the proof, but leaving this here for future visitors.The way I see it, this is wqs binary search/IOI Aliens DP trick(at least for the DP). Intuitionally, we can see that the recurrence is concave, so we can use the trick here. LinkAlso, we don't need to add cost t to both A[i] and B[i]'s(as in dotorya's solution), just adding to A[i]'s and modifying DP to only take a B[i] after taking some A[j] (j < i) takes care of it, I think it is also easier to observe concavity in this DP(code: 27438988).
•  » » » » » 4 years ago, # ^ |   +20 Actually I was asking for a proof of my greedy algorithm, not the binary search.Your resources will be useful for others though, thank you :)
 » 4 years ago, # |   +10 In problem C, how to find minimum-cost flow with flow value exactly k?
•  » » 4 years ago, # ^ |   +10 You can make another sink T1 and an edge T -  > T1 with capacity k and cost 0.
•  » » » 4 years ago, # ^ |   +10 That's a lot simpler than I thought. Thanks!
•  » » 4 years ago, # ^ |   +7 Or run your MCMF algorithm for k iterations.
 » 4 years ago, # |   0 At the bottom of problem L it wrote In her travels, Heidi has learned an intriguing fact about the structure of her social network. She tells you the following: The mysterious determinant that you might be wondering about is such that it does not cause strange errors in your reasonable solution... Did we mention that Heidi is a weird cow?Hmm, I wonder how would the determinant of the system ever trouble with a participant while solving the system of linear equations. I didn't thought of including them in my consideration as they usally cost O(N^3) to compute, don't they?
•  » » 4 years ago, # ^ |   +5 See the editorial for an answer :)
 » 4 years ago, # |   0 It looks like O(n^3) solution should get TL in N, but my 27410692 gets AC in 3.7s.
•  » » 4 years ago, # ^ |   0 Yeah, really, i optimized my DP and it also passed http://codeforces.com/contest/802/submission/27417184
 » 4 years ago, # | ← Rev. 3 →   +28 Sample input here http://codeforces.com/contest/802/problem/O looks weirdly similar to that one here http://main.edu.pl/pl/archive/pa/2013/rap :P. That's a great problem, so that's nice that more people got to experience solving it, but you got lucky no Polish guys who knew where this problem comes from participated because they would get AC in first 10 mins.
•  » » 4 years ago, # ^ |   +10 That's a great problem, so that's nice that more people got to experience solving itOur thoughts exactly :)We estimated that not many such people would participate, and we were right (but also: one of the reasons this was unrated). On the other hand, some people seem to have had prewritten solutions to B (and some of them got RE due to too small arrays in their codes :P). We did anticipate that the problem would be known in theory, because it is a classical question, but didn't know that it was posed as a contest problem.
•  » » » 4 years ago, # ^ |   +15 For B, I remember at least that it was set at FARIO 2009 (a joint French-Australian contest) and the problem and solution was described in Last Supper from IOI 2012. I think it's one of the most standard problem that I haven't heard an official name for.
 » 4 years ago, # |   0 For problem N,I saw a few solutions using dp with binary search.Can someone please explain this approach.
•  » » 4 years ago, # ^ |   +3 See dotorya's comment above.
•  » » » 4 years ago, # ^ |   0 didn't read the comments.Thanks anyways.
 » 4 years ago, # |   0 I read the editorial and didn't understand the question H. Can anybody explain with an example?
•  » » 4 years ago, # ^ |   +10 For k=1 we have s=a and p=a.Let's try . We have p=a, u is empty and we arrive at p'=ab and s'=abbb.Now, let's try : p=ab, u=bb (because p+u=s), so p'=abc and s' = ab + c + bb + cc (I added + for clarity). You can check that indeed you can find "abc" in "abcbbcc" 7 times.One more example: . The only difference from previous one is construction of s'=ab+cc+bb+cc
•  » » » 4 years ago, # ^ | ← Rev. 2 →   0 Thank you. There is something that i couldn't figure out. If I want to generate 6, what should I pick s and p for k=2?
•  » » » » 4 years ago, # ^ |   +10 The simplest is s=aa and p=a but any pair such that p appears 2 times in s will be ok.
•  » » » » » 4 years ago, # ^ |   0 Thank you again. You helped a lot.
 » 4 years ago, # |   -26 Your rating in the next round will be the votes of this comment! So everyone upvote me for high rating!
 » 4 years ago, # |   -23 Hey, superb post. Thanks for sharing. Gmail Helpline Number UK Gmail Help Number UK
 » 4 years ago, # |   0 In K we had to find the subtree in which it would have possibly ended his journey for that in the editorial the approach is formulate another dp in which we store the maximum possible value if the journey ended in that subtree dp[node][true] but can't we just search for that unvisited segment that has a maximum value by keeping a global maximum variable and add that in our ans. Please explain why it is incorrect to do so? My Code 27472638
•  » » 4 years ago, # ^ |   0 "can't we just search for that unvisited segment that has a maximum value by keeping a global maximum variable and add that in our ans "- NO this is not optimal 5 2 0 1 100 0 2 2 2 3 5 2 4 3 a small test case .