### cyand1317's blog

By cyand1317, history, 7 months ago, ,

Selamat petang!

The curtain has fallen on Codeforces Round #487 (Div. 2). Have you enjoyed the problems themselves? Or the stories? Or both? Neither?

I hadn't ever intended to create a hard contest, believe me... (╥﹏╥) The author will try to find ways to estimate the difficulty better in the future. Also, stronger pretests, notes taken.

Anyways, hope you've all enjoyed the challenges you've faced, and gained something from this round. Congratulations to those who performed well, and commiserations to those waiting for their next chance to shine (^_−)−☆

Below are the tutorials of all problems. Feel free to point out mistakes (if any) or share your ideas in the comments! I might be overcomplicating or confusing something > <

Short Ruby solution
Noam's C++ solution
Python solution for the original problem as well as for the last challenge
C++ seemingly-brute-force solution
Model solution
Model solution
Model solution

See you next time! I hope I'll be welcomed. Cheers!

•
• +144
•

 » 7 months ago, # |   +23 Editorial is cool like announcement!
 » 7 months ago, # |   +51 A bit simpler C solution picture
•  » » 7 months ago, # ^ | ← Rev. 2 →   +6 It is more difficult instead ...
 » 7 months ago, # |   +15 Super fast editorial !
•  » » 7 months ago, # ^ | ← Rev. 3 →   0 Everything in this contest is great !!
 » 7 months ago, # | ← Rev. 3 →   +2 Can anyone please explain the solution for C in English? Edit: I believe I understand now. Thanks!
•  » » 7 months ago, # ^ |   +1 Just replace the one-cell components with their surroundings. Sorry for not making this clear.
•  » » » 7 months ago, # ^ |   0 Can you please explain it a little more Thank you!!
•  » » 7 months ago, # ^ |   0 Video solution with explanation: https://youtu.be/BLnY8UrSR_o
•  » » » 7 months ago, # ^ |   0 Thanks!
 » 7 months ago, # |   +23 woah, rating change of 195 in just 30 hours for me.boss feeling
 » 7 months ago, # |   +26 Really enjoyed today's contest, thank you cyand1317
•  » » 7 months ago, # ^ |   +41 (≧▽≦)
 » 7 months ago, # |   +50 Found a smaller solution for A, simply changed product to XOR in your Ruby solution ^.^ 67 charactersputs gets.codepoints.each_cons(3).any?{|x,y,z|x^y^z==64}?'Yes':'No'
 » 7 months ago, # |   0 I know that in problem C, number of components cannot exceed 100. But will your solution work for inputs like "1225 1225 1 1" if we remove that constraint?
•  » » 7 months ago, # ^ |   0 no
•  » » 7 months ago, # ^ |   0 It will work for large input, but the number of rows will exceed 50. The problem is designed so that there are a huge number of ways to construct an anwer.
•  » » » 7 months ago, # ^ | ← Rev. 2 →   0 For "1225 1225 1 1", we can do it 50x50 grid. But with your solution I don't think it's possible. Can you extend your solution to work for such inputs ?
•  » » » » 7 months ago, # ^ |   +1 I can add one special check and make a 50×51 grid just for this case (> <)The best solution I can come up with so far is here. I have no idea how to extend it...
 » 7 months ago, # |   +20 My solution to C:
•  » » 7 months ago, # ^ |   +11 Mine!
•  » » 7 months ago, # ^ | ← Rev. 2 →   +8 Mine for input 100 100 100 100
 » 7 months ago, # | ← Rev. 2 →   -11 for p==n in Problem B there was no way to conclude answer is No as only about positive p the condition was mentioned. This cost me whole problem. sad wordings :(
•  » » 7 months ago, # ^ | ← Rev. 2 →   -38 Yes it kind of amazes me that the setter penalizes for such a case which is ambigous.I was on the verge of solving C and then my solution got hacked due to this thing n==p and it never came to my mind that this could be the error.Really disgusting from a contestant point of view.That was shit of a testcase.
•  » » » 7 months ago, # ^ |   +5 ever heard of the word "edge case"?
•  » » » » 7 months ago, # ^ |   0 Yes it had been a edge case had the answer been Yes because there existed no "i" for which the constraint was valid.
•  » » » » » 7 months ago, # ^ |   0 There is no valid i so yes it is a period. but the question asked whether it is not a period. so the answer is the opposite that is No.
•  » » » » » » 7 months ago, # ^ |   0 I got that already.Peace.
•  » » 7 months ago, # ^ |   +14 This is known as a vacuous truth.
 » 7 months ago, # |   0 Please explain C, can't really seem to get the editorialist's code also to mention the picture too!! :P
 » 7 months ago, # | ← Rev. 2 →   +17 Ques C was Interesting.Good Contest this. cyand1317.
 » 7 months ago, # | ← Rev. 2 →   +11 It is easier to solve D (in linear time for sorted input) if u divide points on basis of sign of x and v and u won't have to worry about fractions. http://codeforces.com/contest/989/submission/39163175
•  » » 7 months ago, # ^ |   +11 Actually dividing them into two sets according to the sign of v is enough: 39187157.
•  » » » 7 months ago, # ^ |   0 I think it should be *it > x in this line. while (it != minus.end() && (*it < x || wmax * (long long)(*it — x + l) <= abs(*it + x + l)))
•  » » » » 7 months ago, # ^ |   0 No, it shouldn't.
•  » » » » » 7 months ago, # ^ |   0 @Jakube how did you derive the formula you used to check for valid pairs?
•  » » » » » » 7 months ago, # ^ |   +1 To be honest, only by reading the editorial. I used the same formula: .But I don't see why the editoral then goes further distinguishing cases. From the sketch, (and the fact that the slope is less or equal than 45˚) is it really obvious that it isn't necessary. For each xu just find the first xv that satisfies the condition, and then all xw > xv automatically satisfy the condition.
•  » » » » » » » 7 months ago, # ^ |   0 @Jakube can you explain how you derive that then? I'm confused about why it is not x_v-x_u+l on the left side, since x_v > x_u...
•  » » » » » » » » 7 months ago, # ^ |   0 Sorry, it should be .I just copied it from the editorial, and it seems like they have it wrong too.
•  » » » » » » » » » 7 months ago, # ^ |   0 Fixed now, thanks for pointing out.
 » 7 months ago, # |   +1 my solution for C
 » 7 months ago, # | ← Rev. 5 →   +30 My solution on C with input 100 100 100 100not fine,but can accepted! :) pic
•  » » 7 months ago, # ^ |   0 the prettiest one so far
 » 7 months ago, # | ← Rev. 2 →   0 My C solution's pictureThanks for your efforts :)
 » 7 months ago, # | ← Rev. 2 →   +35 My picture for C (test 100 100 100 100): Picture
•  » » 7 months ago, # ^ |   0 This is pretty compact!
 » 7 months ago, # |   +22 Thanks for this super-ultra-hyper-mega-meta-great-delicious-wonderful contest cyand1317 !
 » 7 months ago, # |   0 hope every time editorial is this quick
 » 7 months ago, # |   0 IN EDITORIAL OF E -> can you please explain this line "For each l, we should calculate the average of f(m−1)u such that the u-th point lies on l"
•  » » 7 months ago, # ^ |   0 1 more ques.. IN the code of E what have u used GCD function for in struct line?
•  » » » 7 months ago, # ^ |   +3 GCD is used to normalize the equation of the line in order to remove duplicates. This is not the only way, though.The sentence above means, for example, if points A, B, C lie on a certain line l, then the final probability is if l is chosen.
•  » » » » 7 months ago, # ^ |   0 thanks man.. :)0
 » 7 months ago, # |   0 My code runs perfectly okay on test 18 of B but it is giving an WA on test case 18. I am using g++ compiler on my pc. Can't understand why, since the output it produces in the test case should not be produced by program logic.Submission link : My Submission Any insight would be helpful.Thanks!!!
•  » » 7 months ago, # ^ | ← Rev. 2 →   0 To explain why:diff = n — p => 1 (for n = 3 & p = 2) for (int i = 0; i < diff; ++i) runs only once flag == false (since v[0] = 1 and v[2] = 0 output is "No" which is produced by my compiler but WA on codeforces. Can't understand... PLEASE HELP!
•  » » » 7 months ago, # ^ |   0 try debugging in custom invocation.
•  » » » 7 months ago, # ^ |   0 actually No is the wrong answer correct answer in 100.
 » 7 months ago, # |   +7 Here's my C for input 100 60 13 1Very fun question, good job cyand1317 :)(My solution handles 1 ≤ a, b, c, d ≤ 145.)
•  » » 7 months ago, # ^ |   0 This is the simplest to understand of all solutions but maximum number of components can only be 145 :)
 » 7 months ago, # |   +38 With a pattern like this you can handle cases with a,b,c,d <= 385.
•  » » 7 months ago, # ^ |   +13 Nice insight! This can be modified to achieve 577. Hope this makes sense... ↑ Maximum ↓ "Eating" strategy
•  » » » 7 months ago, # ^ |   0 Does this eating strategy really work? Because you eat almost the same number of two colors.
•  » » » » 7 months ago, # ^ |   +5 In the top-left area we have only eaten blue ones. It should be easy to eat yellow and pink ones then.We can do this for each area separately, eating an arbitrary number of each colour, so I think it does work.
•  » » » » » 7 months ago, # ^ |   0 We also ate yellow ones.
•  » » » » » » 7 months ago, # ^ |   0 Oh wait, i missed something.
•  » » » 7 months ago, # ^ |   0 You can also use the middle vertical strip. Then you can do a,b,c,d<=600
•  » » » » 7 months ago, # ^ |   +5 Oh great!
 » 7 months ago, # |   +7 ()
 » 7 months ago, # |   0 problem D 2 10 100 2 1 1 -1 answer should be 1 but the standard puts 0 it shouldn't be xu
•  » » 7 months ago, # ^ |   +8 In the problem, no clouds should intersect at the beginning. The model solution doesn't handle cases where they initially intersect.
 » 7 months ago, # | ← Rev. 2 →   0 Mine is a little bit too complicated.A = 100, B = 90, C = 70, D = 50 cries
 » 7 months ago, # | ← Rev. 3 →   +12 my solution
•  » » 7 months ago, # ^ | ← Rev. 2 →   +6 You are so strong!
 » 7 months ago, # | ← Rev. 3 →   +2 For those looking for an idea to solve problem C, this is a really simple solution. Feel free to check my submission if you want. The code works fine even for a,b,c,d <= 300. This is the case where A = B = C = D = 100 :)
 » 7 months ago, # |   0 Thanks to the writer! I love this contest!
 » 7 months ago, # |   0 My solution to E is actually in O(n4 + 30n3 + qn3)-time, where 30 is the laziness cutoff mentioned in the editorial. It passed the system test just because I was lucky :) http://codeforces.com/contest/989/submission/39167167I enjoyed this contest very much. Thanks!
•  » » 7 months ago, # ^ |   0 You are excellent!! I also know a strange solution..Because of the convergence of probability , we can make the mi no more than 60 .So we can get the probability by dp and brute force. And it can also pass the system test with high speed.Forgive my poor English...
 » 7 months ago, # |   0 http://codeforces.com/contest/989/submission/39180094 This is my solution for Div 2-B , I think it will also work for bonus-3(n<=10^5), but I am not sure,please correct me if i am wrong .Thanks in advance :)
•  » » 7 months ago, # ^ | ← Rev. 2 →   0 You need, in bonus.3, to cope also with bonus.2.
•  » » » 7 months ago, # ^ |   +3 Okay , I didn't know that , thanks
•  » » » » 7 months ago, # ^ | ← Rev. 4 →   0 Sorry if I misunderstood you ^_^. I meant by my reply that not just the constraint on range of n was added in bonus.3, but also they added that you need to print the lexicographically minimum string if the answer is not NO.And as I saw from your code, it doesn't cope with bonus.3, because it doesn't print the "lexico. mini."And for solving this, I suggest to replace each '.' with '0' (after making sure that the answer is not NO) then iterate over the string from index 0 to n - p - 1 (inclusive) (indexing from 0) to see if there is an index i that setisfy s[i]! = s[i + p].If there is, then this is the answer, because we shouldn't change any character other than the dots and this string is not p-periodic.If no, we should iterate over the string from right to left, and the first index we see and it was a dot before replacing dots with zeros, we should change it to '1', and the resulting string is the answer.Hode my answer is correct :)Please cyand1317, judge this solution for bonus.3 in problem B ^_^.
•  » » » » » 7 months ago, # ^ |   +3 thanks for the solution :)
•  » » » » » 7 months ago, # ^ |   +3 Quite close — try this :) 5 3 0..00 
•  » » » » » » 7 months ago, # ^ |   0 True. I need when I iterate from right to left to check for the first index i that setisfies both following two condition:1) i in [0, n - p - 1] or [p, n - 1].2) s[i] = '.' before the replacement.True?Thank you very much :)
•  » » » » » » » 7 months ago, # ^ |   +3 True ^ ^
 » 7 months ago, # | ← Rev. 2 →   0 Problem E turns out to be an exact Markov chain problem xD
•  » » 7 months ago, # ^ |   0 plz explain the problem
•  » » » 7 months ago, # ^ | ← Rev. 6 →   0 let each entry represent the probability (ex : 1 → 2 is the probability of going from 1 to 2)Then, A2 =(this one is bit hard to recognize, by the way.)By generalization,where ... can be any sequence of n - 1 vertices The answer is MAXline(sum - of - the - (row, column)[Mline * Am - 1]) where Mline is initial state of for each line and (row=index of vertices belongs to initial line), (column=vertex index of destination) (i'm sorry this must be hard to understand, but this is my best explanation) (and with some optimizations originally written in editorial)You can google 'markov chain' for much more elegant explains.
•  » » » » 7 months ago, # ^ |   0 nice,thanks
 » 7 months ago, # |   0 Can someone please explain the solution (visualization) of problem D.
•  » » 7 months ago, # ^ |   0 Think x axis as position and y axis as time. then,For moon, x = ywFor cloud with speed s, x = sy + xo and x = sy + xo + l where s is 1 or -1
 » 7 months ago, # |   +8 The idea is simple:Implementation is here: http://codeforces.com/contest/989/submission/39190964
•  » » 7 months ago, # ^ |   0 how did you created the above image?I used below link but it is giving me boundaries and grid bordershttps://golovanov399.github.io/grid/rect_grid_draw.htm
•  » » » 7 months ago, # ^ |   0 Read editorial solution for problem C :)
 » 7 months ago, # | ← Rev. 3 →   0 solution for (100 100 100 100) Full code at — http://codeforces.com/contest/989/submission/39193422 Interesting problem!! :)
 » 7 months ago, # |   +9 In problem D editorial: "For a pair of rightwards-moving cloud u and leftwards-moving cloud v, their intersection in the diagram has a top corner of ... ", is y coordinate correct? I think it should be (x_v + l — x_u) / 2 instead of (x_u — x_v + l) / 2 (x_u < x_v, right?)
•  » » 7 months ago, # ^ |   0 Yes, I think it's a typo.
•  » » 7 months ago, # ^ |   0 Fixed, thanks!
 » 7 months ago, # |   0 My sol for C 100 100 100 100 Spoilersol for 1 1 1 1 Spoiler
 » 7 months ago, # |   +8 cyand1317 Sir, I know basic programming like i am able to solve Div2 A,B, C(sometimes)...... Can you tell me what all topics(and from where) i should do to improve so that i will be able to solve div2 C and Div2 D much easily....... Thankyou...
•  » » 7 months ago, # ^ |   +2 Personally I would suggest this blog (see bold text at the end). Also FYI there is this blog.
 » 7 months ago, # |   0 I love your D, such a cuuuuuuute and beeeeeeeeeautiful idea!Rua~ cyand1317
•  » » 7 months ago, # ^ |   +16 Thaaaaaaank yooooooooou!It's not duliu! Not ever! > <
•  » » » 7 months ago, # ^ |   0 Surely not DuLiu, it's kinda standard of neat and fresh problems.
 » 7 months ago, # |   0 My simple solution! INPUT: 77 33 22 144
 » 7 months ago, # |   +1 no time to read the story...
 » 7 months ago, # |   0 Super cool contest.!! This contest helped a lot of participants to improve their ratings as the questions were well-framed and logical.
 » 7 months ago, # |   0 Bonus. D Solve for intervals of various lengths, with possible intersection at the beginning.
•  » » 7 months ago, # ^ |   0 The only difference is we have lu and lv in the inequality instead of a unified l, right?
•  » » » 6 months ago, # ^ | ← Rev. 2 →   0 UPD:got it
 » 7 months ago, # |   0 Video solution for Problem C: https://youtu.be/BLnY8UrSR_o
 » 7 months ago, # |   0 I get wrong answer in Pro E for Error of accuracy, and my 1.5 hours run out. Maybe we should pay more attention to the calculation of plane geometry...
 » 7 months ago, # |   0 For problem E instead of taking average I didcases:1) M turns starting from point in S 2) First turn from point not in S + M-1 turns starting from point in Sand I took max of resulting vectorIt seems precision is worse, and it failed seventh test case by 7*10^-6 (error margin is 10^-6). Now is it just precision problem or is there some logical error. And how to improve the accuracy?