### robinyu's blog

By robinyu, 5 years ago,

Mabuhay!

I am honored to announce Codeforces Round #419. It will take place tomorrow, on June 17, 17:35 MSK.

The problems in this round are written by me, robinyu. I believe it is the first Codeforces round with a Philippine writer. I would like to extend my heartfelt gratitude to kevinsogo, AlexFetisov and winger for their invaluable help in testing the problems, KAN for his endless patience and support in preparing the contest, and of course MikeMirzayanov for the absolutely amazing Codeforces and Polygon platforms.

In this round, you will be helping Karen in her day-to-day routine.

There will be pretty pictures, drawn by the lovely Kazenokaze. Do not miss the round!

Both divisions will be given five problems and will have two hours to solve them. Keeping with authentic Codeforces tradition, scoring will be announced right before the round.

As a matter of course, you are highly recommended to read all the problems; though problems are arranged by expected difficulty, you may find some problems easier than others.

I hope you will enjoy the problems as much as I did writing them!

The scoring for this round is:

Div. 1: 500 — 1250 — 1500 — 22502250
Div. 2: 500 — 1000 — 1500 — 2000 — 2750

Good luck, and I wish you all high ratings and bug-free code!

Update: Congratulations to all winners!

Div. 1 Div. 2
2. yutaka1999 2. ChillingDream
3. W4yneb0t 3. WA_TLE
4. Um_nik 4. TLEwpdus
5. eddy1021 5. Tian.Xie

Special congratulations to Radewoosh for his second consecutive Div. 1 round victory, and to both him and yutaka1999 for solving all tasks!

Thanks for your patience. The editorial has been posted. Hope it was worth the wait!

• +724

 » 5 years ago, # |   +99 VoHiYo anime round VoHiYo
 » 5 years ago, # |   +53 finally, a rated round after such a long wait...
•  » » 5 years ago, # ^ |   -106 is it rated?
•  » » » 5 years ago, # ^ |   +736
•  » » » » 5 years ago, # ^ |   +88 What website you used to make such great pictures like this? And is the girl customizable? :')
•  » » » » 5 years ago, # ^ |   0 wow
•  » » » » 5 years ago, # ^ | ← Rev. 15 →   +15 Моя попытка во время контеста: http://codeforces.com/contest/816/submission/27854137 (WA 126)Моя попытка после контеста(тот же код): http://codeforces.com/contest/816/submission/27876220 (ACCEPTED) Почему АБСОЛЮТНО ОДИНАКОВЫЕ КОДЫ получают WA и AC??????Лог чекера Can't find file C:\Contesters\Work\invoker-prod\work\codeforces2\5fce135e23ca31c3af3931016c4ef202\check-2b11d4eec984eb8ac636a09dfb665d94\run\output.fd0138e687.txt.UPD: все исправлено!
•  » » » » » 5 years ago, # ^ | ← Rev. 2 →   +10 I think you should send this to MikeMirzayanov
•  » » » » » » 5 years ago, # ^ |   +4 Done
•  » » » » » 5 years ago, # ^ |   +3 This error might be somehow connected with your nickname :)To be seriously, it's strange bug. I hope you will get your honest rating scores back.P.S. And why minuses? People are so agressive to others problems?
•  » » » » 5 years ago, # ^ | ← Rev. 3 →   0 My rating was getting around +120, but in the end got only -1
 » 5 years ago, # |   +63 Now I know I was right not to let Araragi Karen appear in round #418... in case of possible conflicts.
•  » » 5 years ago, # ^ |   +219
 » 5 years ago, # |   +88 karen i can be your onii-chan
•  » » 5 years ago, # ^ |   +12 How about being my brother in god and working for egypt?
 » 5 years ago, # |   +42 Hope for short statements.
•  » » 5 years ago, # ^ |   +160 Hope for ecchi (see artist's weebsite).
 » 5 years ago, # |   +57 I never understood why the scoring is announced right before the round if it's always the same...
•  » » 5 years ago, # ^ |   +46 Not always, actually. There might be minor changes like it was in the previous one (i.e C and D were worth 1750 points instead of common 1500 and 2000)
•  » » » 5 years ago, # ^ |   0 Why is scoring always announced just before the round, Could anyone tell what was the idea behind this tradition initially ?
 » 5 years ago, # |   -18 hope it likes rick and morty's contests , good luck for every Autako
 » 5 years ago, # |   -16 Woho.. never thought of getting an Anime theme based Round.. Made my day.
 » 5 years ago, # |   +79 So we had a Bakemonogatari round and now an anime round. Things are looking bright for CF.
•  » » 5 years ago, # ^ |   0 What round is the Bakemonogatari round?
•  » » » 5 years ago, # ^ |   0 418
•  » » » » 5 years ago, # ^ |   0 Thanks!
 » 5 years ago, # |   +14 Very interesting topic..
 » 5 years ago, # |   0 "...you may find some problems easier than others."In other words, There will be a math problem at DIV 2 C or D :(
•  » » 5 years ago, # ^ |   0 Well said .. :) Div 2 D
 » 5 years ago, # |   +56 Oh, there was no rated round for Div.1 for 27 days! But today, there is a contest that probably rated for Div.1 so I'm especially looking forward to this contest. (Previous rated round for Div.1 is Codeforces Round #415.
 » 5 years ago, # |   +3 I think all anime fans will participate on this round.
•  » » 5 years ago, # ^ |   0 I don't think so. This is not a place where one who is into anime participate the contest just because it's anime-themed. Anyway I haven't ever expected to see a contest involving anime character, great surprise.
•  » » » 5 years ago, # ^ |   +19 Many of my friend (Japanese) says, "I like the character Kujou Karen, so I'd like to participate in this round (Actually I don't know even who is Kujou Karen) Another interesting fact in Kujou Karen in competitive programming is KujouKaren in Atcoder is very strong and got 5th in MUJIN Programming Contest. So much anime culture in competitive programming... surprised.
•  » » » » 5 years ago, # ^ |   +106 Actually, the user KujouKaren in atcoder is me...I've tried to register the username KujouKaren in CF but I found that this ID has been used KujouKaren.
•  » » » » » 5 years ago, # ^ |   +9 You can take the handle in the next new year I guess if you wish as KujouKaren is inactive for 2years and hasn't participated in any rated contest.
 » 5 years ago, # |   +17 just informed my friend about the round and he is a big time anime fan.he canceled his date today :P
 » 5 years ago, # |   0 anime round , sound cool to me .
 » 5 years ago, # |   +109 Karen is so cute DA☆ZE~⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄
•  » » 5 years ago, # ^ |   -8 LOL I r8 8/8 Alice and Karen <3
 » 5 years ago, # | ← Rev. 2 →   0 Why can't I register for the contest? The system tells me that I've registered but I really have't. Upd: Fixed
•  » » 5 years ago, # ^ |   0 xam
 » 5 years ago, # |   +1 nice round ! now i think every one want's to help karen in her day-to-day routine ;D
 » 5 years ago, # |   +3 It is a welfare of otuka!!Nice picture.
 » 5 years ago, # | ← Rev. 2 →   +20 I registered, then cancelled the registration and now can't register again.(the other computer says that I'm registered)
•  » » 5 years ago, # ^ |   0 Same to me
 » 5 years ago, # |   +27 Wow! A writer from my home country :) Congrats to kevinsogo for being top 1 in Google Code Jam 2017 Round 3 :D
 » 5 years ago, # |   +40 It will be hard to concentrate on problems.
 » 5 years ago, # |   +19 As we know, competitive programming is moemoeSports! I'm looking forward to the CUTE image and clear problem statement!
 » 5 years ago, # |   +37 Well, I think I am the only one that watched the entire series of Kiniro Mosaic just because it will be featured on this contest. God bless moe anime.
 » 5 years ago, # |   +3 I hope that problems statement very clear.
•  » » 5 years ago, # ^ | ← Rev. 2 →   -7 I don't think so cause of pics and story !
 » 5 years ago, # |   +5 Short description will be helpful everybody.
 » 5 years ago, # |   +5 Please I hope no 10 min delays.
 » 5 years ago, # |   -9 wow anime on codeforces these days ._.
 » 5 years ago, # | ← Rev. 2 →   +11 How about the "right before the round" scoring distribution ?UPD: Fixed
 » 5 years ago, # |   0 is this contest will delay 10 minutes as normal ? or will be different and start in exact time :D
 » 5 years ago, # |   +9 Very unusual Scoring for div.2 :D
 » 5 years ago, # |   -23 i know what to comment to get upvotes!
•  » » 5 years ago, # ^ |   -21 take some downvotes too :P
 » 5 years ago, # |   -21 2nd problem will be tougher? it seems so seeing the scoring distribution!
 » 5 years ago, # |   0 is there something wrong with codeforces. I have been trying to submit C for 20 minutes but I couldn't submit. Its like there's no response from codeforces site.
•  » » 5 years ago, # ^ |   0 Same happened to me but they fixed it
•  » » 5 years ago, # ^ |   0 Please fix it soon. I am unable submit yet.
•  » » » 5 years ago, # ^ |   0 Go to your contest dashboard. Ask it to the "Ask a question" section below.
•  » » » » 5 years ago, # ^ |   +1 thanks man. submitted only 2 minute before contest.
 » 5 years ago, # | ← Rev. 3 →   0 edit: nvm
 » 5 years ago, # |   -47 The comment removed because of Codeforces rules violation
•  » » 5 years ago, # ^ |   -13 Same here,please reply!
 » 5 years ago, # |   +1 First time opened last problems, because of pics.
 » 5 years ago, # |   +10 How to solve D?
•  » » 5 years ago, # ^ |   +97 Write brute force solution. Run brute force on all vectors (0,0,0, ... , 1, ... 0) of length k, to get weight of each individual element. Recognize the pattern. Even vs. odd n makes a difference, and even vs odd also does, you're looking for patterns depending on modulo 4. Verify against bruteforce. Step (optional): Prove the correctness. Step: Pray that you didn't miss anything.
•  » » » 5 years ago, # ^ |   +8 I recognized all patterns except n % 4 == 3. Could you please explain it?
•  » » » » 5 years ago, # ^ |   +18 If you have n % 4 == 3 and you don't know how to answer it, just apply one step and you have n % 4 == 2 and you know how to solve it.
•  » » » » » 5 years ago, # ^ |   0 What you mean by apply one step?
•  » » » » 5 years ago, # ^ |   0 If you could find the patterns for n % 2 then you could transform n % 2 == 1 into n % 2 == 0 by bruteforcing one step.
•  » » » » » 5 years ago, # ^ |   0 Could you please improve the explanation? Thanks!
•  » » » » » » 5 years ago, # ^ |   +11 My solution was simple: find the relation for when n is even. If it is odd, make 1 step for it to become even. Note through the drawing below the problem that the operations are still at the same order so you can apply what you found for n % 2 == 0.If you had the relation for n % 2 == 1 you could start from n % 2 == 0 and apply the step 3 times, now the operation is the same as starting from n % 2 == 1 (it starts adding) and you can use the relation you have. Other than that kind of stuff, you need to note that each number will influence the answer independently and then do some bruteforce solution to find some pattern from inputs like 0 0 1 0 0 0 0, at least I think almost everyone did that.This is straight from my code, it might be helpful to you (it's in portuguese and comb is a binomial coeficient):// par -> j par = comb(n / 2 — 1, j / 2) // par -> j impar se n / 2 % 2 == 0 é negativo, se não é positivo // par -> j impar comb(n / 2 — 1, j / 2)// impar -> transforma no par e resolve
•  » » » » 5 years ago, # ^ |   +15 For odd indices the coefficients are .Even indices are .Maybe you can find one formula for both.
•  » » » » » 5 years ago, # ^ | ← Rev. 9 →   +36 When you miss the case n=1 and you don't believe on correctness of your pattern
•  » » » 5 years ago, # ^ |   0 If you manage to recongize one pattern it is enough, since you can build the other in a brute way from the recognized pattern.
 » 5 years ago, # |   +37 How to solve Div1B :(
•  » » 5 years ago, # ^ |   +6 I think to use binomial coefficients. (Pascal's triangle)
 » 5 years ago, # |   0 Is Div1 — B solvable using matrix exponentiation? would also be interested to know other methods. TIA
•  » » 5 years ago, # ^ | ← Rev. 2 →   0 What will be the transition function? The transition function will change depending on the level we're at. eg: from level 10 to 5 has a different transition function than 12 -> 6.In short, according to my understanding, we can't. To use mat-exp we need a consistent transition function, that doesn't depend on level.
•  » » 5 years ago, # ^ | ← Rev. 2 →   +13 I passed pretests by finding pattern of the coefficients (Huh). There were 4 cases, (parity of n, parity of (n/2))
•  » » » 5 years ago, # ^ |   +5 Wow! nice. I was looking for a similar pattern but didn't think it would depend on parity of n/2.
 » 5 years ago, # |   0 Hack for Div 2 C ?
•  » » 5 years ago, # ^ |   0 3 2 1 1 1 1 1 1answer : 2 (1 for each column)
 » 5 years ago, # | ← Rev. 2 →   0 Hack for Div2 C?
•  » » 5 years ago, # ^ | ← Rev. 4 →   +13 Typically, when n > m. 5 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
•  » » » 5 years ago, # ^ |   0 Thanks My output was 5 and then all rows :/
•  » » » 5 years ago, # ^ |   0 The answer is 5 row 1 row 2 row 3 row 4 row 5 right?
•  » » » » 5 years ago, # ^ |   +3 No, answer is 3 because problem asks for minimal number of moves(I saw it only now).
•  » » » » » 5 years ago, # ^ |   +3 Omg I missed it too. And most people in my room...
•  » » » » 5 years ago, # ^ |   +3 I forgot about the min even though I checked both row and columns :'(
•  » » » » » 5 years ago, # ^ |   0 I made the same mistake first but realized it just before the contest ended while testing my own solutions. Managed to resubmit just in time :D
•  » » » » 5 years ago, # ^ |   0 using the minimum number of moves
•  » » » » 5 years ago, # ^ |   0 No: 3 col 1 col 2 col 3
•  » » » 5 years ago, # ^ |   +21 Is it the right answer?3col 1col 2col 3
•  » » » » 5 years ago, # ^ |   +8 Yes.
•  » » » 5 years ago, # ^ |   0 fuck :(
•  » » » 5 years ago, # ^ | ← Rev. 2 →   +1 I can not believe this... I knew this exception but accidentally typed n instead of m...if(n
•  » » 5 years ago, # ^ | ← Rev. 3 →   +2 Sometimes you need to start from columns not from rows... Consider a table:010 010 010 010 010 010My solution because of this was hacked... Bye bye rating :D
 » 5 years ago, # |   +9 Div 2 C is from an old Cook-Off
•  » » 5 years ago, # ^ |   0 You had an opportunity to solve it in 5 minutes =)
•  » » » 5 years ago, # ^ |   0 I was making sure , that I dont mess up anything.
•  » » 5 years ago, # ^ |   0 Its easier than that . Here one matrix is always all zeroes . In the question you mentioned in your link, the other matrix is different and you need to make both matrices equal . Div 2C is an easier version of that .
•  » » » 5 years ago, # ^ |   0 Hmm, but can't we apply the same technique on both matrices and compare the residue matrix after all operations? If the residue is same, then they are same.
 » 5 years ago, # |   +18 That feeling when you screw up your rating because of one "if" condition in Div1 A :(
 » 5 years ago, # |   +24 The Art of the Covfefe lmao
 » 5 years ago, # |   +1 div 2B please ?
•  » » 5 years ago, # ^ | ← Rev. 2 →   0 I solved it with Segment Tree + BIT. For each given n range, update the range with segment tree. Then for each i from 1 to 200000, point query with segment tree checking whether it is >= k. If it is, then update point i in BIT with +1Later, for each query, just do a range query with BIT.P.S. I think it's pretty much overkill. Maybe others have much simpler idea.
•  » » » 5 years ago, # ^ |   +9 No need to use BIT/segment tree when all queries are after update.Code
•  » » 5 years ago, # ^ |   +3 Do you know partial sum? for i [ 1, n ] arr[a]++; arr[b+1]--then find the cum. sum in the arr[].and then also do the cum sum in the array to find if the arr[i] is >= k.then just ans is for query l to r cum[r]- cum[l-1]
•  » » » 5 years ago, # ^ |   +1 Something like this link
•  » » 5 years ago, # ^ |   0 I think its solvable by sorting the intervals for left and right segment and then using a prefix counter subsequently to count how many items within range are greater than or equal to k.I had a problem with trying to find the number of segments that pass through index i while iterating through the intervals but was able to resolve it only too late. Now i feel very sorry
 » 5 years ago, # | ← Rev. 2 →   0 Is there the case of the type :2 1 1 1(div 2 C)in the pretests ?
•  » » 5 years ago, # ^ |   0 I don't think so. This is one of the hacking test.
»
5 years ago, # |
0

# HACKATHON COMING

 » 5 years ago, # |   +24 How to solve D? Is it involved inclusion-exclusion principle?
 » 5 years ago, # | ← Rev. 2 →   0 Div2B is very similar to this problem — http://www.spoj.com/problems/UPDATEIT/
•  » » 5 years ago, # ^ |   0 I think they are pretty different.
•  » » » 5 years ago, # ^ |   0 I used the exact strategy mentioned in the link above . I have done the above mentioned one.
 » 5 years ago, # |   +8 Was D variation of pascal triangle or something? can anyone tell what was wrong with my code
•  » » 5 years ago, # ^ |   +3 try this testcase: 1 1
•  » » » 5 years ago, # ^ |   +5 Ohh Crap! Thanks though :)
 » 5 years ago, # |   0 Can someone tell me what particular cases may occur in div1D? I've spent 30 minutes trying to find a bug and didn't find anything...WA on pretest 4. Has it happened to anyone else, too? If so, how did you fix it?
 » 5 years ago, # |   0 Solved C 3 minutes after ending...
•  » » 5 years ago, # ^ |   0 Solved C 20 seconds after endings...
 » 5 years ago, # |   +1 How to solve div2 B? -_-
•  » » 5 years ago, # ^ |   +4 Do you know partial sum?for i [ 1, n ] arr[a]++; arr[b+1]--then find the cum. sum in the arr[].and then also do the cum sum in the array to find if the arr[i] is >= k.then just ans is for query l to r cum[r]- cum[l-1]
•  » » 5 years ago, # ^ |   -10 Solved it with segment tree.
•  » » » 5 years ago, # ^ |   0 Overkill
•  » » » » 5 years ago, # ^ |   0
•  » » » 5 years ago, # ^ |   0 B would have been interesting if each query had its own 'k'. That would have been a good question on merge sort tree .
•  » » » » 5 years ago, # ^ |   +3 No need for merge sort tree if queries come after updates.
•  » » » » 5 years ago, # ^ |   0 Then, i would have gone for segment tree and a node will be a sorted vector of elements lying in segment. Now for query, just binary search to find. Query would be O( log(n) **2)How is merge sort tree approach different from that ?
•  » » » » » 5 years ago, # ^ | ← Rev. 2 →   0 It's the same . :) Such a segment tree is called a Merge Sort Tree
•  » » 5 years ago, # ^ |   +2 Let's say we calculate 2 arrays: int l_cnt[200200]; int r_cnt[200200]; l_cnt[t] — how many intervals start with temperature t?r_cnt[t] — how many intervals end with temperature t?Then we can figure out in O(1) the number of intervals covering some given temperature t in the following way: int covering_intervals = n - l_cnt[t + 1] - r_cnt[t - 1]; 
•  » » 5 years ago, # ^ |   0 think about sum A[1...r] then you need to add 1 to [l, r]. 1<=l<=r<=a. think about sum A[1...r-1] then you need to add 1 to [l, r]. 1<=l<=r<=a. think about sum A[1...r-2] then you need to add 1 to [l, r]. 1<=l<=r<=a. You store array D[1...n] Add 1 to D[l], subtract 1 from D[r+1]. And them D[i]=D[i-1]+D[i]. Here you have a prefix array Check if D[b]-D[a-1]>=k.
•  » » 5 years ago, # ^ |   0 With Binary Search code
•  » » » 5 years ago, # ^ |   0 Can you explain why your code works ?
•  » » » » 5 years ago, # ^ | ← Rev. 4 →   +1 For each temprature check in how many ranges it lies within the range (with binary search explained below) For all those tempratures whose value is >=k we use prefix array dp[i] = dp[i-1]+1(if its is more than k) else dp[i] =dp[i-1] 3.now every query can be answered in O(1) time .Total complexity is O(nlogn)Now to check in how many ranges a tempratue values lie within you can use upper_bound and lower_bound function from stl calculate the lower_bound from the right array as it will return no. of values in right array more than that value , after that we need to subtract those values from the above values whose left index is more than the required temprature so we use upper_bound function , and the difference between the two is our answer , now if it is >=k than we should include it else not.obviously , we need to sort left and right arrays
•  » » » » » 5 years ago, # ^ |   0 Thank you for the explanation . I did realize that we had to apply BS but I applied it completely on a different criteria that gave me many TLE's
 » 5 years ago, # |   +3 My C is failing System Test today :(
 » 5 years ago, # |   0 Canany one give me a clue for problem B? I think solution is binary search but I can't code :(
•  » » 5 years ago, # ^ |   0 Use prefix array
•  » » » 5 years ago, # ^ |   0 Can you give me some recommendations link for prefix array ?
•  » » 5 years ago, # ^ |   0
•  » » » 5 years ago, # ^ |   0 can you explain it to me ?
•  » » » » 5 years ago, # ^ |   0 see my above comment pleaselink
•  » » » » » 5 years ago, # ^ |   0 thanks you !
 » 5 years ago, # |   +1 How to solve Div2 C?
 » 5 years ago, # |   0 Of course, a coupon cannot be used without buying the corresponding good Anyone forgot this case like me ? :'(
•  » » 5 years ago, # ^ |   +21 No, because then you can just use all the coupons :P
•  » » » 5 years ago, # ^ | ← Rev. 2 →   0 No i don't think so what about this case :4 42 12 1 110 9 12 1 3We can not use all the coupons
•  » » 5 years ago, # ^ |   +3 If you can use a coupon but not buy the good, Then you can just use all the coupons but buy only the lowest (C-D) items as long as you can. In other words, equivalent to the problem, you have an array of values (equal to C-D), find the max no of items you can buy with sum <= B.
 » 5 years ago, # | ← Rev. 2 →   0 Div 2 C was an 99% copy of this problem. MRTNSFRMJust wrote what was in the editorial. Edit: Did not notice bhishma's comment.
 » 5 years ago, # |   0 What was complexity of your solution for C? Mine was brute force that works in 0(500 * n * m)
•  » » 5 years ago, # ^ |   0 You can do it in if you just find minimum in row/column and substract it. Since max answer is roughly max(n, m) * 500, it is faster. However, your complexity should be totally fine.
•  » » » 5 years ago, # ^ | ← Rev. 2 →   0 I did exactly what you mentioned . Hope i pass system tests . This is my first time that first 3 passed pretests.. Update : I got TLE in 3rd :/
•  » » 5 years ago, # ^ | ← Rev. 2 →   0 Also you can use DP+priority Queue to do it in (n*m). Link to my code here
•  » » 5 years ago, # ^ |   0 Thanks
 » 5 years ago, # |   +34 Spent a lot of time on C, found a DP approach, proved the correctness, proved the time complexity is less than , submitted 15 minutes before end of contest and got WA on pretest 3. Panicked.Re-read the statement to find out that Di is the discount and not the price after discount. Phew. Hope it holds.
•  » » 5 years ago, # ^ |   +31 I am guessing it is similar to the question "Barricades" from "Looking for a challenge" book.
 » 5 years ago, # |   +48 I'm guessing div1-E was inspired by Bathroom Stalls from this year's GCJ Qualification Round?
•  » » 5 years ago, # ^ |   0 So that's why it looked familiar!! The new 10^18 bounds though...
 » 5 years ago, # |   +15 Problem E is similar to Problem C from this year Qualifications Round in Google Code Jam, but this problem was more challenging.
 » 5 years ago, # |   0 Can anybody please tell me, if there is a segment tree + lazy propagation approach for Div2 B ??
•  » » 5 years ago, # ^ | ← Rev. 2 →   0 Yes, it can be done in that way too but it can be solved easily using prefix array. Look at this code — 27855143
•  » » 5 years ago, # ^ |   0 You can just find all temperatures that suit and answer on queries using binary search
•  » » 5 years ago, # ^ |   0 Make an array of pairs with size 200000.let the first element of the pair as start of some of the given ranges and the second as the end.now iterate over all values from 1 to 200000 cumulating sum like the following:sum += a[i].first , sum -= a[i].second. but before subtracting the end check if the sum on index i is greater than or equal to K then on another array mark i as true or just 1.now build a segment tree (regular segment tree of sum) on the array of marks. and answer regular sum query on it.sorry for detailed explanation :D code
 » 5 years ago, # |   +21 What a fucking problem D (Div.2) that was garbage :/
•  » » 5 years ago, # ^ |   +2 Shit > problem D
•  » » 5 years ago, # ^ |   0 Why you think that ? [I got WA in last 5 minutes but still need to find out why :v ]
•  » » 5 years ago, # ^ |   0 if your king paid that billions for improving mathematical books instead of trump you wouldn't have said that :)
•  » » » 5 years ago, # ^ |   0 did you ? :p
 » 5 years ago, # | ← Rev. 2 →   +3 What is the time complexity of this solution for Div2 E/Div1 C?? Is this O(n2) or O(n3). I think it is the latter, what do you think?
•  » » 5 years ago, # ^ |   +18 It is actually O(n^2) because for each u, the total number of iterations is the number of pairs(x, y) such that lca(x, y) = u. That sums up to number of all pairs (x,y) in the tree.The sad thing is that I thought O(n^2 * log(n)) was fine so I sorted each node's descendants to calculate f[u][i][0] instead of running another DP :(
•  » » » 5 years ago, # ^ |   +19 Yeah that's sad indeed I thought that this solution will be slow so I didnt program that and instead I was trying to optimize it.Shit. :(
 » 5 years ago, # | ← Rev. 2 →   +13 815E - Karen and Neighborhood is a simplified version of task 3 (OGLEDALA) from Croatian olympiad in informatics 2015 March 28th=(
 » 5 years ago, # | ← Rev. 2 →   +26 +12:-2
 » 5 years ago, # |   0 Div2C/Div1A — https://www.codechef.com/problems/MTRNSFRMDiv1E — https://code.google.com/codejam/contest/3264486/dashboard#s=p2 (very similar)As I know, Div2E/Div1C also appeared in some past contest.It loks like author is very good at copying problems)
•  » » 5 years ago, # ^ |   +29
•  » » 5 years ago, # ^ |   +9 What's wrong with div1 E being similar. Can't the author be inspired by the problem? Most people here did the GCJ but did not solve this anyway.
•  » » 5 years ago, # ^ |   +16
•  » » 5 years ago, # ^ |   0 Div1C is similar to Codechef Snackdown 2017 Elimination Round problem BLACKCOM (just some weeks ago).
•  » » » 5 years ago, # ^ |   0 only because both problems are "dp on tree" then you consider them similar? in my opinion they are quite different
•  » » » » 5 years ago, # ^ |   +8 Problemsets are quite different. I mean the solutions of optimizing O(n^3) to O(n^2) are similar.
 » 5 years ago, # |   +11 160+ tests in problem A X_X
•  » » 5 years ago, # ^ |   +3 398 tests in problem E O_o Maybe it's E just because of that? :D
 » 5 years ago, # |   +170 My last 2 minutes: I somehow had unused functions (but compiled) that were dependent on my local template :|
•  » » 5 years ago, # ^ |   +13 That's the closest clutch I have ever seen! Great job at saving your rating haha
 » 5 years ago, # |   +25 Sorry, Karen I couldn't help you in Task: C,D,E :(
 » 5 years ago, # |   -10 My contest submission status: The Time and the Memory value is increasing, and I can even make two trapezoids! That's interesting! :D
 » 5 years ago, # |   +10 Very slow system testing :p
•  » » 5 years ago, # ^ |   +5 That's because Div2 C has over 175 testcases!
•  » » » 5 years ago, # ^ |   +5 Ohhkk
 » 5 years ago, # | ← Rev. 2 →   +10 E peeled of easy binary searches in main and ifs for k=1,2 That's ... unexpected ;p(this function tells "how many people will be placed on interval (l, r) if l and r are already occupied and people will not move in if distance is smaller than dis or it is equal to dis and their position is > bd)
•  » » 5 years ago, # ^ |   +20 Taking someone's problem and making it just a bit harder is definitely not the best way to create programming problems.
 » 5 years ago, # | ← Rev. 2 →   +74 Well... were I more skillful, I'd have solved C easily.Were I more tactical, I'd have skipped C quickly and would have solved D sooner and probably solved E.I can't believe I can't solve a task that 100+ ppl can solve. If this happens in IOI, I can put my head through a wall.
•  » » 5 years ago, # ^ |   +20 That's already well known trick mentioned many times on CF that such dp runs in O(n^2) and not in O(n^3) and solving it in O(n^3) is pretty straightforward
•  » » » 5 years ago, # ^ |   0 Well...I always solve this kind of tasks using dp on dfs sequences, which somehow don't work(at least I think) on this task.
•  » » » » 5 years ago, # ^ | ← Rev. 5 →   +17 What do you mean by that? I do it in a most standard way of doing dps on trees Dfs(v) { initialize dp[v] for child in children[v]: Dfs(child) merge dp[v] and dp[child] } where dp[v][cnt][coupon] is cheapest cost of buying cnt guys from v's subtree so that I used coupon on v if coupon==1
•  » » » » » 5 years ago, # ^ |   0 How to prove the complexity is indeed O(n2)?
•  » » » » » » 5 years ago, # ^ |   0 Search the comments here in this page...
•  » » » » » » » 5 years ago, # ^ |   0 Thanks for the help.
•  » » » » » » 5 years ago, # ^ |   0 For each subtree you'll make Size of previous subtrees * Size of this subtree, the sum of everyone of these is the number of pairs of vertices (u, v), so it is O(n^2).
•  » » » » » » » 5 years ago, # ^ |   0 Thanks for the help.
•  » » » » 5 years ago, # ^ | ← Rev. 3 →   0 well it works in O(n2 * logn) in this task I guess
 » 5 years ago, # |   +6 As a forever yellow, I am very happy about the difficulty of Div1B and Div1C — usually Div1B is somehow clear (save for maybe some implementation challenges), and Div1C is just too difficult. This difficulty distribution definitely felt more fun. Your mileage may vary, for others this difficulty jump might have been to much between Div1A and Div1B ... what are your thoughts?
 » 5 years ago, # |   +30 It's surprising week sample, week pretest and cute image :P
 » 5 years ago, # |   +150 was there any better way to solve div1B than observe pattern in this
•  » » 5 years ago, # ^ |   -8 I don't think so. I also tried to do it like this (but did a mistake in a brute xdd) and people I talked to also did same thing. You can also magically guess what the answer will be and check it manually :D.
•  » » » 5 years ago, # ^ |   0 I would like to know closed form for n%4 == 3 and n%4 == 0 as well. Will wait for that editorial :)
•  » » » » 5 years ago, # ^ |   0 For it is .
•  » » » » 5 years ago, # ^ |   +3 for n%4 == 0 , let x = (n-2)/2 , then the sequence is xC0 , -xC0 , xC1 , -xC1 , ... , xCi , -xCi , ... xCx , -xCx. for n%4 == 3 , try to observe nth and the n-1th row , its either [n-1][i] + [n-1][i-1] or [n-1][i] — [n-1][i-1] depending on parity.
•  » » » » » 5 years ago, # ^ | ← Rev. 3 →   0 Since pattern for n%4 == 0 is really nice one. We can just perform the operation for n%4 times and then use the pattern for the n%4 ==0. One more observation to make is that if the last operation you performed in above step ( to reduce to n%4==0 ) is '+' then now our starting operation in the new scenario will be '-' which is different then the standard problem. Only change we need to make now is to use the same formula as mentioned by @majk but just omit the pow(-1,i) part ( all the values will be +ve if we start with a '-' operation ) my code
 » 5 years ago, # |   0 good pretests for div2 C
 » 5 years ago, # |   0 system testing is too slow! :(
 » 5 years ago, # |   +2 Very slow system testing.
 » 5 years ago, # |   +22 Am I the only who couldn't hack any solution because whenever I tried to open some solution it wrote that I need to install the newest version of Adobe flash player?I spent 15 minutes and finally installed new version, but I still was recieving such messages.
•  » » 5 years ago, # ^ |   +13 I wanted to try hacking 5 minutes before the end so I just gave up after seeing that message.
•  » » 5 years ago, # ^ |   +30 I always use Chrome but for hacking I use firefox xD (because I get same error and I don't know how to fix it xD)
 » 5 years ago, # |   +59 A screencast of my (pathetic) performance.
 » 5 years ago, # |   0 Maybe I should study more math before participating future contests as of late so many DIV2 C,D are using maths. So the algorithms I know are not needed here. I wish I am a math guy lol.
 » 5 years ago, # |   0 Just some complexity checking here. Can anyone tell me why my code runs only in 62ms ? http://codeforces.com/contest/816/submission/27862413 I use 4 nested loops with O(500*n*m*(n+m)) right here. Shouldn't 10^9 at least takes 1 second in codeforces judge?Thanks.
 » 5 years ago, # |   +28 ah i could hack a lot of solutions(( but i wasted time trying to solve D
 » 5 years ago, # |   0 How to solve Div2 D
•  » » 5 years ago, # ^ | ← Rev. 2 →   0 ans = k0 * a0 + k1 * a1 + k2 * a2 + ... + k(n-1) * a(n-1)Corner cases:n % 4 == ???:1: t = n / 2 — 1;Then k = {C(t, 0), 0, C(t, 1), 0, ... }2: t = (n — 1) / 2Then k = {C(t, 0), C(t, 0), C(t, 1), C(t, 1), ...}Other two cases for exercize.
•  » » » 5 years ago, # ^ |   0 How did you come this to solution, observation?
•  » » » » 5 years ago, # ^ |   0 yes, just bruteforce to 20
 » 5 years ago, # |   +93 :3 , just :3
•  » » 5 years ago, # ^ |   +10 Two first places in a row? Incredible :D
•  » » » 5 years ago, # ^ | ← Rev. 2 →   +19 Marcin_smu did it some time ago, it can be seen that he's my "coach" on my university XD
•  » » » » 5 years ago, # ^ |   +12 Yea, 318 and 319. Poland strong :D
•  » » » » » 5 years ago, # ^ |   +56
•  » » » » » 5 years ago, # ^ | ← Rev. 2 →   +11 On 318 and 319, Marcin_smu both took 1st place, mnbvmar (also from Poland) both took 2nd place.
 » 5 years ago, # | ← Rev. 2 →   +5 Why so many people (including me) forgot to handle the n>m case (div2 C)?.... and nobody hacked my solution :'( :'(
•  » » 5 years ago, # ^ |   0 Mine was hacked 2 minutes before the end... :D
 » 5 years ago, # |   +38 the best thing in this contest that the problems was clear and easy to understand thanks robinyu
 » 5 years ago, # |   +40 It's over, I have the high ground!
•  » » 5 years ago, # ^ |   0 How to solve Div2 E/Div 1 C?
 » 5 years ago, # |   +8 Finally I am blue again !!I hope, I can see pink in future.
 » 5 years ago, # |   +7 Finally expert!!! <3
 » 5 years ago, # |   0 Div. 2 C n > m case. RIP.Sometimes, I just wish. D:
 » 5 years ago, # | ← Rev. 2 →   +6 When will the next round be?
•  » » 5 years ago, # ^ |   +1 In July =)
•  » » » 5 years ago, # ^ |   0 nope!
 » 5 years ago, # |   +17 My screencast here (99th place :C)
 » 5 years ago, # |   0 I cant figure out why my code is giving negative output on test 19 for Div1 B. Link http://codeforces.com/contest/815/submission/27857089
•  » » 5 years ago, # ^ |   0 In your code, a1 can be negative. So, say a1=-1e9, a2=1e9; Then (a1-a2+MOD) is still negative.
•  » » » 5 years ago, # ^ | ← Rev. 3 →   0 Okay but see this submission(i printed a1 and a2 if ans is negative) http://codeforces.com/contest/815/submission/27868207. So a1 is not negative here.
•  » » » » 5 years ago, # ^ |   0 Okay, This time the bug's in the other branch, ans=(a1+a2)%MOD. Here, a1+a2 becomes negative, since a2 is negative.
•  » » » » 5 years ago, # ^ |   0 just add if(ans < 0) ans += MOD
 » 5 years ago, # |   +3 Can not get any idea about Div2 C..Help needed about realizing the solution of the problem ..
•  » » 5 years ago, # ^ | ← Rev. 2 →   +5 If you fix the number of times you add to the first row, all other variables get fixed automatically. Let no of times you add to row i be ri and that of column j be cj. If you fix r1, cj = arr[1][j]-r1. Now, ri = arr[i][1] — c1. After that you just check if all ri>0 and cj>0 and ri+cj == arr[i][j]. Then it is valid. If it is valid, take the minimum number of steps, which is sum of ri and cj. There are atmost 500 values possible for r1, as 0<=r1<=500 because 0<=arr[1][1]<=500.Time complexity is O(M*n*n) where M is max value in array. Code
 » 5 years ago, # |   +2 In which category does problem C(Div 2) falls in?
•  » » 5 years ago, # ^ |   0 Greedy maybe?
•  » » 5 years ago, # ^ |   0 ad-hoc and math..
 » 5 years ago, # |   0 Had some weird errors during the contest in div2 C. Four five submissions. Please look into it so that it doesn't repeat. submission
 » 5 years ago, # |   0 Can anyone tell me why my C answer is wrong.?https://pastebin.com/TzpachRc
•  » » 5 years ago, # ^ |   +1 You want to find the solution with the minimal number of moves. The solution 50 col 1 col 2 ... col 50 consists of less moves than your solution.
•  » » » 5 years ago, # ^ |   0 sorry i just figured it out. :( my bad
 » 5 years ago, # |   0 Nice both pictures and problems
 » 5 years ago, # |   0 ARIGATO GOSAI MASSHH for the round... :D
 » 5 years ago, # |   0 How to prove that the order of making changes in various rows and columns in div2C is interdependent .... Someone plz help i have trouble in understanding....
•  » » 5 years ago, # ^ |   0 I mean can't we apply the transformation in any order i.e why do we only need to do the rows first and then the column or viceversa
•  » » » 5 years ago, # ^ |   +1 Each transformation can be represented by a matrix addition. And those operations are commutative.
 » 5 years ago, # |   0 How to solve Div 2 B without a segment tree?
•  » » 5 years ago, # ^ |   0 Using cumulative sum.
•  » » 5 years ago, # ^ |   +2 I used binary search. First, for each temperature you check if it's admissible or not(you can do it just iterating through them and calculating balance of segments) and add it to the array if it is(array will be sorted if you start from t = 1). Then on queries you just do binary search to find the first and the last suitable temperature for current query. My code: http://codeforces.com/contest/816/submission/27853021
 » 5 years ago, # |   +64 My screencastHope you find it interesting
 » 5 years ago, # |   0 This is my submission for problem A:27853670It says my solution failed at pretest 10. If i run that on my mac i'm getting the right answer which is 20. Can anybody explain where it went wrong...
•  » » 5 years ago, # ^ |   0 You are accessing the strings s1 and s2 but they are empty, which is undefined behavior. That's why it may work on your mac but not with the online judge.
•  » » » 5 years ago, # ^ |   0 Got it.Thanks :)
 » 5 years ago, # |   +3 My approach for Div2 C: first calculate minimum element in each row .it denotes the number of operation we can do in corresponding row.and store it inside a vector named row Now calculate the maximum element among each element we have calculated in the previous step.let's denote it by mn now for each column calculate its maximum element.let denotes it by mx .Then abs(mn-mx) will denotes the number of operaetion in a column, and store abs(mn-mx) inside a vector named col now to check for invalid case.make a new matrix lets say ff.each cell(i,j) of the ff matrix will be row[i-1]+col[j-1].if g!=ff then print -1 else answer exit now to calculate the answer.just calculate the sum of all element in vector row and col lets saya answer is ns1; Now do the step-1 for column and step-3 for row and store the result inside vectores col1 and row1, and calculate the answer ns2 answer will be minimum of nsand ns2 see modeMy code
 » 5 years ago, # |   0 Any idea for solve div 2 problem D.
 » 5 years ago, # |   0 Ok, I've upsolved Div2C in greedy approach after the contest, but I don't understand why it works! Can anyone explain?
 » 5 years ago, # |   0 What problem B? I didn't understand :(( help me!!!
•  » » 5 years ago, # ^ |   0 You are tasked to find the sum of lengths of segments (all their values >= k) within given intervals [l,r] (both ends inclusive).This problem is tailor-made for segment tree/fenwick tree. My solution using segment tree: link.Of course, a fenwick tree solution is similar but easier.
•  » » » 5 years ago, # ^ |   0 thanks :)) and I can sol the problem B
•  » » » 5 years ago, # ^ |   0 Your solution is 4 times faster than mine, but I can't understand how?Your solution's complexity:build: O(NlogN)First loop: O(NlogN)Second loop: O(NlogN)Third loop: O(N)Queries Loop: O(Q)My solution's complexity:First loop: O(N)Second loop: O(N)Queries loop: O(Q)So overall your solution runs in O(NlogN) and mine in O(N), but your solution passed in 486ms and mine in 1933ms.My code linkP.S: I submitted it in practice, does it have any effect.I have seen other's solution there's too takes around 1800ms.
•  » » » » 5 years ago, # ^ |   0 After adding ios_base::sync_with_stdio(0) (that makes cin/cout faster) your solution runs in 670 ms, so it's much closer to 500ms :)
•  » » » » » 5 years ago, # ^ |   0 Woah! I didn't know it could have that much impact on time, 3X faster. Thanks
 » 5 years ago, # | ← Rev. 2 →   0 I used java for solving 816A. It worked perfectly fine on my computer ( I have JAVA 8 too) but not on codeforces. It gave a runtime error. Following is the code snippet: // s: scanner StringBuilder in = new StringBuilder(s.readWord()); StringBuilder rev2 = new StringBuilder(in); StringBuilder rev = rev2.reverse(); //Error starts here int rm = Integer.parseInt(rev.substring(3,5)); //ERROR HERE // Thing is, if in = "05:39", for my computer rev.substring(3,5) = "50". However for codeforces, rev.substring(3,5) = ":5". Hence, for codeforces rev.substring(4,6) = "50", while for me it is an ArrayIndexOutOfBoundError Can anyone tell me why is this happening?
•  » » 5 years ago, # ^ | ← Rev. 3 →   0 I tried your solution on 1. "05:39" 2. "05:39 " It showed me the same error on (2), so I guess the test cases have a space character at the end and that is causing some problem.
•  » » » 5 years ago, # ^ |   0 The scanner is set to stop amd ignore ' ' and '\n'. Is there any other characters I should ignore?
•  » » » » » 5 years ago, # ^ |   0 I guess this is the problem. Thanks a lot for your help, I was really confused!
•  » » » » » » 5 years ago, # ^ |   0 No problem!
•  » » 5 years ago, # ^ |   0 Hello, frag.jdkI think i found the error but if you can share your complete code i can be sure about it.Here is what i think : the error is the in the rev.substring(3, 5). If you are working with integers and then trying to make a string like if hh = 12 and mm = 55 you create a string eaquals to (12:55) in other word some sort of concat... you will for sure get a run time error.Why? imagine you have mm = 59 and you want to increment it to 60 then you which will give you 0. and imagine you have hh = 0 which you will increment to 1 the string will be "1:0" not "01:00" rev.substring have range from 3, 5 which are out of "1:0"'s range.I hope i made it clear.
 » 5 years ago, # |   0 I have solved 2 problems and want to know why my answers are skipped, what is the reason???
•  » » 5 years ago, # ^ |   0 It means you cheated
•  » » 5 years ago, # ^ |   0 Either you have cheated or somebody who has copied your code submitted it prior to yours.!!
 » 5 years ago, # |   +32 Any idea when will the editorials be uploaded ? Thanks
•  » » 5 years ago, # ^ |   +11 May be jury doesn't have their own solutions for all of the problems and they are now trying to understand the code of the guys who solved them.
•  » » » 5 years ago, # ^ |   0 Hi, so to me seems like a notorious coincidence
 » 5 years ago, # |   +37 Waiting for editorial
 » 5 years ago, # |   +133 RNS3's (North Korea, obviously) submissions times:
•  » » 5 years ago, # ^ |   +36 Not to mention subtle differences in coding styles in the submissions on D/E (using LL or ll for long long, cin/cout vs scanf/printf, if (x) vs if(x), ...).
 » 5 years ago, # |   +21 Please provide the Editorial.
 » 5 years ago, # |   +71
•  » » 5 years ago, # ^ |   +20  Editorial will be uploaded by tomorrow I am pretty sure that today is tomorrow for yesterday :D
 » 5 years ago, # |   0 How to solve Karen and supermarket?
•  » » 5 years ago, # ^ |   +6 Notice that coupons form a tree rooted at 1.Then calculate dp[current vertex][total number of goods purchased in the subtree of this vertex][did we apply a coupon for the good in this vertex]. After that the answer will be maximum possible i such that either dp[root][i][0] or dp[root][i][1] is not greater than b.Check my code for details :)27885164
•  » » » 5 years ago, # ^ |   0 Thanks! So we are trying to minimize the cost of i goods at vertex v.
•  » » » 5 years ago, # ^ |   0 Your complexity looks high, close to n^3 :| How did this pass TL?
•  » » » » 5 years ago, # ^ | ← Rev. 2 →   +29 It's not really n^3, though it looks like so.Consider the two for loops for recalculating dp for current vertex u.The outer one indicates how many goods you buy from the subtrees of all children of u, that go BEFORE the newly added vertex v.The inner loop indicates how many you buy from the subtree of v.Thus, the two loops effectively enumerate all pairs of vertices, where two vertices in a pair are FROM SUBTREES OF DIFFERENT CHILDREN OF u, that is, all pairs of vertices with LCA = u. This means, no pair is checked twice, resulting in overall complexity O(n^2)
•  » » » » » 5 years ago, # ^ |   0