### DEGwer's blog

By DEGwer, 7 years ago, ,

Hello.

Codeforces Round #219 will take place on December 13th at 18:00 MSK for both Div.1 and Div.2 participant. Make sure that it will be held unusual　time.

Problem setters are m.kagamiz and DEGwer, and we thank Gerald for helping us to hold this contest, and Delinur for the translation, and MikeMirzayanov for systems.

The score distribution will be uploaded soon, but probably we use the standard scoring system.

UPD1: The score distribution is standard, 500-1000-1500-2000-2500 for both division.

UPD2: Problem B from Div.2 and problem C from Div.1 have some problems, so all submissions to these problems are rejudged. I'm very sorry.

UPD3: Anyone who gets AC two or more times, because of resubmit before clarification, please, write to Gerald, your submissions that should be skipped. Sorry for inconvenience.

UPD4: Now system test has finished, congratulation for winners!!!

Division 1:

1.xudyh

2.tourist

5.al13n

Division 2:

2.pcnc_zLq

3.wuyiqi

And also congrats for rng_58 and permin, who got AC on Div.1 E problem!!

UPD5: Now editorial is uploaded here.

• +262

 » 7 years ago, # |   +9 So interesting! Can you add some information about writers ? I think it will be very interesting to know some about you.
 » 7 years ago, # | ← Rev. 2 →   +59 Finally , a Div1 Contest ! Thank you DEGwer :)
 » 7 years ago, # | ← Rev. 4 →   -102
 » 7 years ago, # | ← Rev. 2 →   -271 downvote me if you can
•  » » 7 years ago, # ^ |   +54
•  » » » 7 years ago, # ^ |   -10 :D
•  » » 7 years ago, # ^ |   -110 And me, please.
•  » » 7 years ago, # ^ |   +25 Now I know what I will do the next time one of my friends forget to logout from their CF account 3:)
•  » » » 7 years ago, # ^ |   -23 It's my account :)
 » 7 years ago, # | ← Rev. 2 →   +14 No Friday 13 special contest?
•  » » 7 years ago, # ^ | ← Rev. 3 →   +3
•  » » 7 years ago, # ^ |   +78 No. The previous one was a Programmer's Day special, Friday the 13th was a coincidental bonus theme. I'm playing with some ideas for the next Surprise Language Round, but this will take more time to prepare. Unless someone else volunteers...
•  » » » 7 years ago, # ^ |   +15 Thanks for making these rounds.
•  » » 7 years ago, # ^ | ← Rev. 3 →   +3 It was Friday 13 special test #13 in problem B (Div. 2) — many contestants failed on this test =(
 » 7 years ago, # |   +20 Problems are Made in Japan!! And anyone knows Products from Japan are of good quality. :)
•  » » 7 years ago, # ^ |   -6 may be
 » 7 years ago, # |   -18 What is the specific reason of being held unusual time ?
•  » » 7 years ago, # ^ |   +28 In Japan, usual time is between 0:30 AM and 2:30AM, so we want to hold the contest in earlier time.
•  » » » 7 years ago, # ^ |   -9 as I guess. asked it because of probability of another reason, thanks.
 » 7 years ago, # |   +13 New authors = new personalities! Hope good problems and short statements! GL & HF!
 » 7 years ago, # |   +8 It's a good time for Chinese participants;thx...But some College students will take a test called "CET4/6" tomorrow,so I think the Chinese participants will reduce...For best wishes...
•  » » 7 years ago, # ^ |   0 Dynamics of participating CF is continuous for no reason, though tomorrow's CET6.
 » 7 years ago, # | ← Rev. 2 →   +116 Glad to see Japanese writers! Recently, I've read a post about Japan (in Russian). Can you approve (or comment) some facts about Japan: On Valentine's Day girls do presents, but not boys. Hentai is extremely popular and teens under 16 can easily and legally buy it. Snowmen are made from two but not three balls. Colonel Sanders (KFC founder) is one of the symbols of New Year Holyday. Many weddings (30%) are result of special meetings organized by parents. Flats and houses in Japan do not use central heating. Many Japanese are afraid of travels and they think that USA is very dangerous for tourists. No tips are in restaurants. Japanese very quick become drunk if drink alcohol. Some subway cars are women only. Is it because of groping?
•  » » 7 years ago, # ^ |   +107 1st, 3rd, 8th, and 10th are just truth. 9th one depends on individuals, but Japanese tend to become drunk very quick. 7th one is not so much, but Japan is very safe country, so some Japanese think almost all of the world is dangerous. For 2nd, 4th, 5th, and 6th, I'm not sure. But I think 4th and 6th is not truth.
•  » » » 7 years ago, # ^ |   +24 Thanks !!! Many interesting things are known about Japan ... :)
•  » » 7 years ago, # ^ |   +103 On Valentine's Day girls do presents, and usually the present is chocolate.And we have White Day one month later than Valentine's Day. On this day, boys do presents for girls, and it is also chocolate.
•  » » 7 years ago, # ^ |   +27 As far as 9. goes, I heard that it's a genetic thing — a large number of Asian population is missing some pathway that helps us cope with alcohol. What a pity! (as I'm writing this, there's a bottle of beer next to me :D)3.: A snowman from 3 balls is too unstable, not to mention harder to make. I can totally understand that one :D should not be true, as far as "legal" goes — it's too weird, even for Japan. (although my knowledge of Japanese culture is based mostly on a certain Gintama anime...) It's not like you can't get any porn easily anywhere in the world...
 » 7 years ago, # |   0 Good luck to everybody!
 » 7 years ago, # |   +6 It's a good opportunity to back Div.1
 » 7 years ago, # |   +10 Oh today is 13th Friday and the problem writer m.kagamiz( m.kagamiz )'s name is Jayson.
 » 7 years ago, # |   0 Good oppurtunity to enter Div1
 » 7 years ago, # |   0 :) it's a FUN competition :)
 » 7 years ago, # |   -16 I am getting extra penalty on problem B Div2 because of that mistake ! I submitted two accepted codes. Is there any hope that penalty can be deleted ?
•  » » 7 years ago, # ^ |   +1 Write a message to jury, via ask a question functionality. That's what I did, and my extra submissions was deleted.
 » 7 years ago, # |   +4 slow judge:((((((((
•  » » 7 years ago, # ^ |   +29 Counting Submissions on Queue is Not Fun
 » 7 years ago, # |   0 My crucial submission on C is hung in the queue for more than 8 minutes. What should be my strategy :( Actually what should be the strategy in such situation???
•  » » 7 years ago, # ^ |   +4 Try hacking or thinking about other problems... or trying to check your submission on C (generate your own testcases and test it yourself, look at the code and think about it again, etc). Or, you can do it like me: just relax :D
•  » » » 7 years ago, # ^ |   0 Last one seems good :p
 » 7 years ago, # | ← Rev. 2 →   -14 При отправке решения задачи В(Div 2) у меня был статус "В очереди" в тичении 10 — 15 мин, а потом выдавало TL на первом тесте, хотя у себя на пк все быстро выдает.Вот решение: http://pastebin.com/NyFYndU0Это у меня в коде ошибка? или с сервером что то было?
 » 7 years ago, # |   0 No hacks round :( (almost)
 » 7 years ago, # | ← Rev. 5 →   +22 i submitted problem B of div-1 at 01:59:48 after a long time of being stuck at it! my hands are still shivering a bit after that last-minute panic! i just hope that it gets accepted! :)EDIT: it (5431756) got Accepted , yay! :)
 » 7 years ago, # |   0 The time limit on C is really close! At least if the intended solution is an O(NM) one... I hope the pretests are as strong as the lack of hacks indicated :D
•  » » 7 years ago, # ^ |   +8 Theoretically, 4 seconds shouldn't be even close for O(45 millions)...
•  » » 7 years ago, # ^ | ← Rev. 2 →   +34 Hush, I'm trying to get accepted here :)
•  » » » 7 years ago, # ^ |   0 There is accepted solution with time. 5429539
•  » » » » 7 years ago, # ^ |   +24 And there is my failed solution with O(NM) time. Wat?
•  » » » 7 years ago, # ^ |   +16 Codeforces administrators' position is it's better to allow good written non-optimal solution to pass, than allow bad written(or on Java) optimal solution to fail. There is some logic, but i think it causes more disbalance.
•  » » 7 years ago, # ^ | ← Rev. 2 →   +45 I have O(M 2) solution. It just took 15 ms. 5431649
•  » » » 7 years ago, # ^ |   0 Could you describe it briefly?
•  » » » » 7 years ago, # ^ |   +22 We know that B i terms are really nothing.Let F(x, t): the minimum sum of |A i - previous_positions| at time t with position xIf you plot this function in fixed t, you'll see that this function consists of some line segments. You get the idea here.If there's a new firework event, one must combine |x - A i| graph into the function.One have to see what happens if the time passes. The shape of the graph will be expanded d × passed_time unit in both sides with lowest point as its center.The maximum number of the line segment is O(M) and the operations described above takes O(numberofthelinesegment) each time. The overall time complexity is O(M 2)
•  » » » » » 7 years ago, # ^ |   0 Can you elaborate a bit more, I am not able to understand this.
•  » » » » » 6 years ago, # ^ |   0 Can you elaborate a bit more, I am not able to understand this
•  » » » » » 11 months ago, # ^ |   0 Actually, it can even be done in $O(M \log M)$.Let's maintain $F(x) =$ maximum happiness we can attain if we end at location $x$. After $f$ fireworks have been launched, $F$ is a polyline with sections having slopes $-f, -f+1, -f+2, \dots, f$. We only need to know its constant value and the $x$-coordinates at which its slope changes in order to uniquely represent it.We can keep a max-heap storing the slope changes left of the constant section and a min-heap storing the slope changes right of the constant section.When $t$ units of time pass, we need $F'(x) = min_{x \in [x - tD, x + tD]} F(x)$. We need to decrease the coordinates of the slope changes to the left of the constant section by $tD$ and increase the coordinates of the ones to the right by $tD$. It can be done lazily by keeping a sum of changes to-be-applied associated with each heap.When a firework is launched at $a$, $F'(x) = F(x) + abs(x - a)$. It can be done by introducing two new slope changes. At most one existing slope change will need to shift from the leaf-heap to the right-heap (or vice-versa). The constant term should also be recalculated.Implementation: 60323635.
 » 7 years ago, # |   0 I have a feeling that today's system test will take a while...
 » 7 years ago, # |   0 Problem D div2/ B div1 core idea ?
•  » » 7 years ago, # ^ | ← Rev. 2 →   0 it can be solved by DP(precalculations) in O(n^5) time .
•  » » » 7 years ago, # ^ |   0 I was thinking about some preprocessing idea, but I didn't get it? What is it ?
•  » » » » 7 years ago, # ^ | ← Rev. 4 →   0 first of all you need to calculate rectangles sums which first coordinate is 1,1; after this you can calculate sum of any rectangles (in O(n^4)):rectangle_sum(i,j,x,y)=sum[x][y]-sum[i-1][y]-sum[x][j-1]+sum[i-1][j-1];if rectangle_sum(i,j,x,y)==0 then we can say that this rectangle consist only zero;using this you can calculate for any (i,j,x,y) number of rectangles which second coordinate(bottom,right) is x,y and consist only zero (in O(n^4)).and finally using this you can calculate ans for any (i,j,x,y); (in O(n^5),or O(n^4)). now you can answer queries in O(1) time.
•  » » » 7 years ago, # ^ | ← Rev. 3 →   +3 actually, it can be solved in time. i think would TLE.EDIT: by i meant . sorry about any confusion my post caused.
•  » » » » 7 years ago, # ^ |   0 Lyrical got accepted in QNM. Wonder how, my QNM takes 17 seconds :/
•  » » » » 7 years ago, # ^ | ← Rev. 2 →   +3 Your solution looks elegant and most importantly small. Could you please explain what does dp[i][j][i+di][j+dj] denote and also provide some intuition behind this "super" recurrence relation dp[i][j][i+di][j+dj] = dp[i][j][i+di-1][j+dj]+dp[i][j][i+di][j+dj-1]-dp[i][j][i+di-1][j+dj-1]+dp[i][j+1][i+di][j+dj]+dp[i+1][j][i+di][j+dj]-dp[i+1][j+1][i+di][j+dj]-dp[i][j+1][i+di-1][j+dj]-dp[i][j+1][i+di][j+dj-1]+dp[i][j+1][i+di-1][j+dj-1]-dp[i+1][j][i+di-1][j+dj]-dp[i+1][j][i+di][j+dj-1]+dp[i+1][j][i+di-1][j+dj-1]+dp[i+1][j+1][i+di-1][j+dj]+dp[i+1][j+1][i+di][j+dj-1]-dp[i+1][j+1][i+di-1][j+dj-1]+check(i,j,i+di,j+dj); 
•  » » » » » 7 years ago, # ^ | ← Rev. 5 →   +6 firstly, although the rest of the code looks elegant and small, i want to remind you that i was in a hurry as i submitted this code at 01:59:48, and i apologize that my recurrence relation looks very messy and requires this post for u to understand.now onto my approach. as you can see i answer queries in , which means dp[i][j][k][l] stores the number of rectangles which contain only 0s in the subrectangle . so from here i will refer to (i,j) as the start-point, and (k,l) as the end-point.di and dj denote the end-point assuming that the start-point is the origin. so if the start-point is (i,j) the end-point would be (i+di,j+dj). the only place to start is a 1x1 square, i.e. dp[i][j][i][j] (where di and dj are both 0), which would be 1 or 0 depending on s[i][j]. clearly we should progressively increase di and dj so that we can use the previous information to compute the currently required info. this is why i fixed di and dj and moved the start-point, rather than fixing the start-point and moving the end-point.below i have elaborated on all the terms in the recurrence relation. i hope u are able to understand now. if not, send me a message and i will get back to u. // i want the rectangles that start at or after (i,j) and end at or before (i+di,j+dj) dp[i][j][i+di][j+dj] = // rectangles that start at or after (i,j) and end before (i+di,j+dj) +(dp[i][j][i+di-1][j+dj]+dp[i][j][i+di][j+dj-1]-dp[i][j][i+di-1][j+dj-1]) // rectangles that start after (i,j) and end at or before (i+di,j+dj) +(dp[i][j+1][i+di][j+dj]+dp[i+1][j][i+di][j+dj]-dp[i+1][j+1][i+di][j+dj]) // i have added rectangles that start after (i,j) and end before (i+di,j+dj) twice, so i should subtract those // rectangles that start at or after (i,j+1) and end before (i+di,j+dj) -(dp[i][j+1][i+di-1][j+dj]+dp[i][j+1][i+di][j+dj-1]-dp[i][j+1][i+di-1][j+dj-1]) // rectangles that start at or after (i+1,j) and end before (i+di,j+dj) -(dp[i+1][j][i+di-1][j+dj]+dp[i+1][j][i+di][j+dj-1]-dp[i+1][j][i+di-1][j+dj-1]) // i have subtracted the rectangles that start at or after (i+1,j+1) twice, so i should add those back // rectangles that start at or after after (i+1,j+1) and end before (i+di,j+dj) +(dp[i+1][j+1][i+di-1][j+dj]+dp[i+1][j+1][i+di][j+dj-1]-dp[i+1][j+1][i+di-1][j+dj-1]) // the big rectangle that starts at (i,j) and ends at (i+di,j+dj) maybe a "good" rectangle +check(i,j,i+di,j+dj); EDIT: really sorry for this long post, but i hope it served its purpose i.e. everything is clear now! :)
•  » » » » » » 7 years ago, # ^ | ← Rev. 3 →   0 This is one super case of inclusion and exclusion. Had my eyes tight shut for nearly 10 mins to get a feel of all the inclusion and exclusion taking place. Hats off sir! The fact that you imagined this and coded this up during the closing minutes of the contest really demands respect.Since the editorialist also seems to have used the same logic and unfortunately, has not cared to explain the intuition behind the recurrence relation, a link to your above explanation should be included in the editorial for others to understand :)EDIT: No corrections. I overlooked the parenthesis. My bad.
•  » » » » » » » 7 years ago, # ^ | ← Rev. 2 →   0 haha thanks. i actually had this logic much earlier than the end of contest, but i was always missing few of the terms, so it was giving me WA on first test on my system. when i finally had the above solution, i submitted it as soon as i saw that it was passing first test (due to time shortage). i tested on second test during the In queue time. i was literally out of breath just after submitting it!about the correction u posted, what i have written above is correct. there is a - sign outside the bracket which will negate all terms inside.yes, ur right. i will post a link to the above explanation as a comment on the editorial.
•  » » » » » » » » 7 years ago, # ^ |   0 Sorry, I overlooked the parenthesis. My bad. Edited my comment appropriately.
•  » » 7 years ago, # ^ |   0 Firstly, you compute prefix sums, so you can check whether a rectangle is good in constant time.You can do memoization for all possible queries.When you get a query, you chcek the biggest rectangle (rectangle described by query itself) and recursively compute number of smaller good rectangles from answers for smaller queries (using inclusion and exclusion).
•  » » » 7 years ago, # ^ |   +13 Or just calculate the answers for all possible queries, and answer them in O(1) time :D
 » 7 years ago, # |   +1 Damn 6 and 12!
 » 7 years ago, # |   -13 Thanks a lot. Very liked problems D and E. Wrong answer 5 in E is thinking same circles good, or I have more errors?
 » 7 years ago, # |   +44 Alert at the very end of the contest was not a great idea — 10 seconds left on the clock, I want to send a solution ... when some stupid alert pops up! I panicked a little bit and failed to send it :( Luckily, my solution was buggy anyway, but I think you shouldn't do alerts in the last 5 minutes of the contest (unless it's about extension). It's better to apologize after the contest (if you want to).Nice round though!
 » 7 years ago, # |   0 can you estimate the waiting time before judge ? :D
 » 7 years ago, # |   0 I wonder why the size of array is not big enough will got a "Wrong Answer", instead of "Runtime Error!" ?
•  » » 7 years ago, # ^ |   +3 Because going out of bounds is an undefined behavior in c++. This means anything can happen. http://stackoverflow.com/questions/1239938/c-accesses-an-array-out-of-bounds-gives-no-error-why
 » 7 years ago, # |   0 Oh man, Div2 A remind me sooooo badly of jubeat. I live in Kazakhstan though so I can play it only on BEEP. BTW Japanese version have way more songs. sigh If I could just simply play Evans through with tests in the Sample XD
 » 7 years ago, # |   +16 Any ideas for non-quadratic Div 1 D, please?
•  » » 7 years ago, # ^ |   +64 O(NlogN). Lets move two pointers and calculate minimal number of vertex in tree, which contains all of this. For doing last part, let's have a set of vertexes sorted in order of in-time in dfs. Then sum of distanses between consecutive vertexes (including last and first) is twiced number of edges in minimal tree.
•  » » » 7 years ago, # ^ |   +5 O(N log^2 N) gets accepted too (binary search on answer, then two pointers with set). TL is really kind.
•  » » » 7 years ago, # ^ |   +5 Awesome!
•  » » » 7 years ago, # ^ |   +8 Thanks! Cool idea to remember.
 » 7 years ago, # |   +6 Counting rectangles was REALLY fun! thanks!
•  » » 7 years ago, # ^ | ← Rev. 2 →   +4 yes it was fun, and the best possible end to it as far as i am concerned, because i made a submission on it at 01:59:48 and got it Accepted! :)
 » 7 years ago, # |   0 Sorry, but if my solution got WA before the clarification, and i submit the right one at last, can i skip the solutions before and return the lost points of WA? Looks like a silly question :p
 » 7 years ago, # |   +5 Good round! Thanks!
 » 7 years ago, # |   0 And also i think 10e16 10e15+1 10e9 is a really interesting test for Problem B in Div2
•  » » 7 years ago, # ^ |   0 Yeah, what a pity for my solution. Just one neglect of "long long" type's overflow! It's ok after using "unsigned long long".......
•  » » » 7 years ago, # ^ |   0 Very Sorry for my hack:( Thought about that... w=w%(k*len)+(w/(k*len)-add)*k*len perhaps this formula is correct:)
 » 7 years ago, # |   +26 Task B,C,D in Div1 are very OI-like. :)E looks nice: After Inversive transform, it becomes: find sets of pair that share a common middle point (and not parallel). Am I right? Well, I spend 40 minutes to figure out a typo in my code. :(
•  » » 7 years ago, # ^ | ← Rev. 2 →   +18 After Inversive transform, there could be three points exactly on a line, we should minus it from the answer. TATEdit : Oops! I haven't read your post clearly. Sorry. But I think it's a quite tricky case.
•  » » » 7 years ago, # ^ |   0 Yes, I get AC now. Without that trick, I think it is only worth 1500p.
•  » » » 7 years ago, # ^ |   +19 Huge congrats on the win!
 » 7 years ago, # |   0 friday13 :) ..that why i did not participate
 » 7 years ago, # | ← Rev. 2 →   +4 div1 C is (fairly standard dp + find max quickly) so I had the idea of it very quickly.however,A and B required a little bit cleverness so I think a lot but couldn't find the solution.I think my skills are declining, thanks to baccalaureate for that :(
•  » » 7 years ago, # ^ |   0 For A it is easy to spot that the best answer is n/2 when after sort, all element from first half is placed in the second half. So the solution is just binary search for each element in the first half, for the smallest elements to be fited in the second half.
 » 7 years ago, # |   +8 Hadn't participated in months. It was a good contest to get back in :)
 » 7 years ago, # |   0 ah my correct solution for problem B got skipped by the judge :(
 » 7 years ago, # |   0 div2 problem B is tricky, calculation would be exceed long long,I noticed this point in contest,but I don't know how to deal with it.And cause me fail system test,also many participant.Then I use double get AC, sad :(
•  » » 7 years ago, # ^ |   0 I used __int64, equals to signed long long. Accepted: 5427927. Sorry for my bad english.
•  » » » 7 years ago, # ^ |   0 Yeah,I see.You are use division and it wouldn't exceed long long.I also think this means but I havn't use it. Then I use multiplication and cause WA.Your means is a good ways too, I think I should consider more, thank you very much! :)
 » 7 years ago, # |   +18 You really SHOULD NEVER USE stack with visual studio 2010. If you want a proof of it, just have a look at this and this . VS 2010 — TLE9, GNU c++ 0x — AC 1123ms
 » 7 years ago, # |   0 http://codeforces.ru/contest/373/submission/5429866could somebody explain me why this code at local returns "YES" but online is "NO"? (mac, x-code)
•  » » 7 years ago, # ^ |   0 atoi(&str[j]) this one considers memory from addres of str[j] to closest zero as C-string and converts it to number. Probably next zero will be the end of string str. So you index dig with something big. Next nobody knows what happen.
•  » » » 7 years ago, # ^ |   0 thk!
 » 7 years ago, # |   0 the test case for which my div2 A http://codeforces.com/contest/373/submission/5421738 gives wa gives the correct output on my machine plz look into in
•  » » 7 years ago, # ^ |   0 could someone plz clarify
•  » » 7 years ago, # ^ | ← Rev. 3 →   +5 DELETED. sorry i was wrong.
•  » » » 7 years ago, # ^ |   0 thanx i dint know this!! does int t[12] = {} ensure that all elements are initialised to 0
•  » » » » 7 years ago, # ^ | ← Rev. 2 →   0 i don't think so, but int t[12]; memset(t,0,sizeof t); makes all 12 elements 0. as u may have guessed, it does not depend on the array size.however, before you use memset, make a note that it only works when u want all values to be set to 0 or -1, not other integers like 1 or 2.
•  » » » » 7 years ago, # ^ | ← Rev. 2 →   +8 i am not sure what exactly happen if you write "int t[12] = {}" but i submit this code and got accepted.5433663
•  » » 7 years ago, # ^ | ← Rev. 4 →   +1 never use fflush(stdin). I commented out your fflush(stdin) lines and it gets accepted.
 » 7 years ago, # |   +23 Round statistics, with images.
•  » » 7 years ago, # ^ |   0 This is super cool!
 » 7 years ago, # |   0 I found out what caused me to TLE on C(div1).Check out 5432941 and 5432965. They only differ in the position of one line: the deque<> is declared once the AC submission, and inside an O(M) cycle in the TLE submission. How come? Shouldn't that just be O(M) additional operations (albeit slow ones)?
•  » » 7 years ago, # ^ |   0 When the size of a vector (or deque) exceeds its capacity (the size of the buffer which is currently allocated for it), its size is increased and the data moved. This incurs a time overhead. When the size decreases, its capacity is not decreased (even if you clear() it). Thus, when the size increases again but no more than what it had already been before, there is no overhead. However, if you make a new deque (and, implicitly, delete[] the old memory block), then you will pay again. This means that if you reuse the same deque, you will save on memory management. Sometimes it is faster to have a globally declared vector and clear it every time, rather than a locally defined one.
•  » » » 7 years ago, # ^ | ← Rev. 2 →   0 I've considered that, but it's test 29. The times ( T[i]) are really close and D = 3, so the deque will only contain at most around 10 elements at once, and so it won't be resized often. It looks like the deque is being allocated much more space than it needs...Besides, it passes test cases 8 and 9, where the allocations are much more massive.
•  » » 7 years ago, # ^ |   +8 I don't know how deque is implemented in cpp, but if there are array resizings, I can see how if you declare the dequeue exactly once, it will never shrink back, and have to reexpand. But if you declared the dequeue multiple times, you would restart with the default initial size and have to reexpand.
•  » » » 7 years ago, # ^ |   0 See my comment above.
 » 7 years ago, # | ← Rev. 2 →   0 for problem c div 2: in test case 21 n=499999 but it does not contains 499999 numbers. please some one go through it
 » 7 years ago, # | ← Rev. 2 →   0 At problem A , this code got Wrong Answer ! sort(a+1,a+n+1); int l = 1 , r = n/2+1; while(l <= n/2 && r <= n){ if(a[r] >= a[l]*2) l++; else r++; } cout<= a[l]*2) l++ , r++; else r++; } cout<
•  » » 7 years ago, # ^ |   0 Because if you don't increment r then you may take an element more than once!
•  » » » 7 years ago, # ^ | ← Rev. 2 →   -8 Output : 250335Answer : 250336if I take an element more than once my Output must be more than Answer !!This is not my wrong , I am sure :)
•  » » » » 7 years ago, # ^ | ← Rev. 2 →   0 The output decreases as the number of pair increases, you are taking an element more than once.Take this example: 3 4 5 10. Your code matches both the 3 and the 4 with the 10.
•  » » » » » 7 years ago, # ^ | ← Rev. 2 →   0 Ok , I know my solution is wrong !But my output must be more than Answer ! Ok ?
•  » » » » » » 7 years ago, # ^ | ← Rev. 2 →   0 No.Youre Output is less than Answer because after you put an kangaroo in another. YOU DO NOT SKIP BOTH OF THEM and it can cause another PAIR , so the Increment of Variable l Because The final result is n-l-1.The Error Pair cause Decrement in output.I can hack your first solution with 4 1 1 1 3 Answer = 3Output = 2
•  » » » » » 7 years ago, # ^ |   -8 I got it ! you are right ! Thank guys :X
•  » » » » 7 years ago, # ^ | ← Rev. 4 →   +1 As far as I see, if you take an element more than once, as the example given by zylber "3 4 5 10", you say that you can input both 3 & 4 within the 10 .. which means the number of hidden is 2 (l = 3) & the number of visible is 2 (n - l + 1) .. while in fact the number of visible should be 3. So your output will be less than Answer, not the other way around.
•  » » 7 years ago, # ^ |   0 It's problem 'A'. If you increment 'l', well, you use a[l] and a[r], else you don't use a[l] and a[r].Sorry for my bad english.
 » 7 years ago, # |   -8 Problem A (div2).I got WA on this submission because of test #13. The error is because of line 9: char row[4];, which should have beenchar row[5];. I know why I need 5 and not 4 (that's because of '\0').On my computer, the test #13 gives the correct answer and I do not receive any errors. Can anyone explain me this weird behaviour and how can I avoid it in the future? Does it have anything to do with the compile and run command?
•  » » 7 years ago, # ^ |   -11 In C++ accessing out-of-bounds elements of array is undefined behavior because arrays are only positions in memory. Sometimes memory after the array is not used and your code passes, sometimes it is occupied, so you do not get a correct value. You cannot check it during runtime someway.The general advise is always to create a bit bigger arrays than you need (e.g. 100010, when n <= 100000).
•  » » » 7 years ago, # ^ |   -16 The general advise is always to create a bit bigger arrays than you need (e.g. 100010, when n <= 100000). My general advise is to use vector instead of static array :) In that case you will find out of range even in small cases.
•  » » » » 7 years ago, # ^ |   +6 Nope, you won't. It also depends on compiler settings. For example, you'll get exception if you use at() or specify a special debug mode define, but operator [] does not check anything by default.So, if you access items around size() + 2, you probably won't get an error without debug.
•  » » » 7 years ago, # ^ |   +8 I don't like that "general advise". If you create an array the size of which you choose arbitrarily, it means you don't rally understand your solution which is the worst thing you never want to face.
•  » » » » 7 years ago, # ^ |   0 I think that kind of thinking is ineffective. If you set the size of an array +5 of what you are expecting, you don't get a worse situation. In contrast, creating an array of a smaller size that is needed based on an incorrect judgement, you may get punished by WA, while the solution basically is still correct.
•  » » » » 7 years ago, # ^ |   +13 It was a very wise comment, it's a shame it got negative feedback.Indeed, arrays of size 10010 is an ugly code. "Competitive programming" could do better than encouraging bad style.
•  » » » 7 years ago, # ^ |   +12 Vanya, I hope you don't teach this to school kids in LKSh, do you?!
•  » » » » 7 years ago, # ^ |   +1 Why not?This is the only possible approach to guarantee that there's no +/-1 errors in C++ while keeping speed of the program (not using vectors + .at() or dynamic arrays).As far as I know, you write in Java and there you can create arrays like that: int[] a = new int[n]; but in C++ it's not the case.
•  » » » » » 7 years ago, # ^ |   +1 Nope. The only possible approach to guarantee that there's no +/-1 errors in C++ is to write code that doesn't have +/-1 errors :)Despite the smile it is not a joke at all.If you believe that your code needs a +10 in arrays size "just in case", would you trust this code to solve some dangerous real life problems?
•  » » » » » » 7 years ago, # ^ |   -8 The goals in competitive programming and production somewhat differ. In ACM-style contests, the goal is to get Accepted for a problem minimizing the wrong submittion count and the time spent on it. In production, the time and "trial-and-error" constraints are not so strict, the main goal is the correctness and soudness of the code. That's why some hacky tricks are very useful in CP, while not welcome in production. So I think this case is perfectly fine and should be encouraged in CP and discouraged in production.
 » 7 years ago, # |   +16 When will rating updated ? No one ask about this. Am I lack of information such a there's some trouble or cheat issue or unrated ? Thanks
•  » » 7 years ago, # ^ |   +6 I guess they are busy answering requests for skipping some submissions in Div2-B.
 » 7 years ago, # | ← Rev. 2 →   0 problem B why did it gave TLE for test case to me ? test case 10000000000000000 1 1 code:long long nod(long long a) { long long b = 0; if(a == 0) return 1; while(a!= 0) { a = a/10; b++; } return b; } int main() { int t; //cin>>t; t = 1; while(t--) { long long w,m,k; cin>>w>>m>>k; long long op = 1; long long length = 0; while(1) { long long temp = (long long)nod(m); long long temp1 = temp * k; long long temp2 = pow(10,temp); long long temp3 = temp2 — m; //cout<<"temp: "<
•  » » 7 years ago, # ^ |   0 it would be better if u posted a link to ur submission.
•  » » » 7 years ago, # ^ |   0 5431626 here is the link for submission
•  » » 7 years ago, # ^ |   0 It is because of the pow function.U can precompute the powers of 10 till 10^18 and strore them and access them in O(1)(I don't know the reason for that much time consumed for the pow function)
•  » » » 7 years ago, # ^ |   0 i got the error pow(10,2) is being casted as 99 (when i run it in custom testing ) again and again.. but i dont know why it is casted to 99 ?
•  » » » » 7 years ago, # ^ |   +12 pow p function uses floating point numbers. Due to rounding errors the result of pow(10,2) is like 99.999999999999 and it is rounded down to 99 during the cast to int.
 » 7 years ago, # | ← Rev. 2 →   +1 Best Rating Change!!! (http://codeforces.com/bestRatingChanges/330812)
 » 7 years ago, # |   0 Can Anyone tell me why 5424683 for 373B - Making Sequences is Fun got WA ?
•  » » 7 years ago, # ^ |   0 overflow w -= (tmp - m) * k * length ;
•  » » » 7 years ago, # ^ |   -8 Go to Python.
•  » » 7 years ago, # ^ | ← Rev. 3 →   -10 everywhere replace long long to unsigned long long
•  » » 7 years ago, # ^ |   0 I did unsigned long long instead of long long and got accepted.
 » 7 years ago, # |   +4 Tutorial??
 » 7 years ago, # | ← Rev. 3 →   0 In contest I tried an intuitive greedy approach for task A div1 — for a size x of a kangaroo, the kangaroo which will hold it will be that with smallest size y such as y >= 2 * x. If y does not exist, I add 1 to solution. However, it turns out this approach is wrong, but I can't find a counter-example (neither I can prove it, as it's wrong :) ). Can someone tell me what's wrong in my thinking, please? L.E. Sorry, I've misunderstood the statement of task :| I thought it's possible to be a "chain" of holds, for example 1 -> 2 -> 4. Thanks all for examples! I'll read statements twice by now on, understanding problem wrong is not fun :)
•  » » 7 years ago, # ^ |   0 Try;1 1 2 4Or 1 2 4 4
•  » » 7 years ago, # ^ |   0 Check this case [2,4,5,8], when you try to find the holder for value 2, your solution will find 4 but it's better to assign 5, so you can assign 8 to hold 4. Your solution will answer 3 for this test case, and the answer is 2.
•  » » 7 years ago, # ^ |   0 4 1 2 3 4Your algorithm will put 1 in 2 but you can do better — 1 in 3 and 2 in 4.It works if you search for y in the second half of the array.
•  » » 7 years ago, # ^ |   0 It depends on from where do u start ur search for "y"Case: 1 2 3 4u should start searching for "y" from the beginning of the second half of items ... which is "3" in this case because the items in the first half have the chance to go into another bigger item into the second half .. while items in the second half do not.
 » 7 years ago, # |   -8 Any proof about DIV1-A problem??
•  » » 7 years ago, # ^ | ← Rev. 3 →   0 Let a set of pairs A = {(x, y): x ≥ 2 * y)} be the solution. Let its size be m Then we can transform this set so that x[0] ≥ x[1] ≥ x[2] ≥ ... ≥ x[m] and y[0] ≥ y[1] ≥ y[2] ≥ ... ≥ y[m]. Proof: Let's sort the pairs in the set by x. Then we pick y[0] and the greatest y of all the pairs. Let the greatest y's index be j. We can change y[0] and y[j]. Then we pick y[1] and change it with the greatest y from the set of pairs with indexes 1..m and etc. End of the proof. Let's sort s array from the task so that s[0] ≤ s[1] ≤ .. ≤ s[n] We can change all x so that x[0] = s[n - 1]..x[m] = s[n - m] and all y so that y[0] = s[m - 1]..y[m] = s[0]. Proof: It's easy to see that x[i] can't be greater than s[n - i - 1] because s[n - i - 1] is the i-th greatest number in s. So x[i] ≤ s[n - i - 1]. And y[i] can't be less than s[i] because s[i] is the i-th smallest number in s. So s[i] ≤ y[i]. End of the proof. So all that you need is run a binary search by m and compare s[n - 1] >  = 2 * s[m - 1]...s[n - m] >  = 2 * s[0]. Have a look http://codeforces.ru/contest/373/submission/5433713
 » 7 years ago, # |   -8 I cannot understand why my this code http://codeforces.com/contest/373/submission/5429910 got TLE and this code http://codeforces.com/contest/373/submission/5437285 got accepted. Can anyone please explain me the reason?
•  » » 7 years ago, # ^ |   0 The parameter of function floor,log10 and pow are all int type, you should use floorl,log10l and powl instead to avoid overflow problem.'
•  » » » 7 years ago, # ^ |   0 Thank you very much.I didn't know about floorl,log10l and powl functions.
 » 7 years ago, # |   -8 Problem E is much easier than problem D in div2.
•  » » 7 years ago, # ^ |   -8 Any idea why my solution for E times out? http://codeforces.com/contest/372/submission/5438314Thanks!
•  » » » 7 years ago, # ^ | ← Rev. 3 →   -8 for (int i = 0; i < M; i++) {... for (int j = 0; j < N; j++) { ... for (int k = left; k <= right; k++) {...} ...}... }It seems something about O(M*N2)
•  » » » » 7 years ago, # ^ |   -8 Yeah, was that too slow? Do you know what the optimal complexity was?
•  » » » » » 7 years ago, # ^ |   0 It is possible to solve this problem with O(NM) complexity by changing your last for() on queue with operation getMax on it.
•  » » » » » » 7 years ago, # ^ |   0 Ahh! I completely forgot that the cost is the same for all on the inner-most for loop and thus you can just choose the max from the range of possible steps. Thanks so much!
 » 7 years ago, # | ← Rev. 2 →   0 Can some one give some hint on problem B. Counting Rectangles is Fun (Div 1 — B). I tried Dynamic Programming approach , but could not able to find the recursive relation Thanks in advance
•  » » 7 years ago, # ^ |   0 it's dp along with Inclusion-Exclusion principle, for each rectangle defined by r1, r2, c1, c2, you can get all the rectangles within it by calling recursively for the rectangles at r1+1, r2, c1, c2 && r1, r2-1, c1, c2 and so on, some rectangles will be counted twice, so you need to exclude their answer and so on (This is inclusion-exclusion principle)You can have a look at this submission 5438353
 » 7 years ago, # |   0 Problem D div2/ B div1 is similiar to UVa 10502 It may be helpful fpr searching some better solutions
•  » » 7 years ago, # ^ |   0 I guess the one here was harder as there were queries, so you had to calculate the answer for every sub-rectangle, the one you posted only asks for the whole grid answer, anyways thanks for sharing this it would really help :) .
 » 7 years ago, # |   +9 Div1.A permits N=5*10^5 at most but I could not attempt such a hack because maximum input for hacks is limited to 256KB in CF. It requires 1MB to describe 5*10^5 numbers and space between them.Is it permitted that code generated test cases for hacks exceed 256KB?
 » 7 years ago, # |   +12 When is the tutorial coming?
•  » » 7 years ago, # ^ |   0 It seems never. Ask for a particular problem.
•  » » » 7 years ago, # ^ |   +5 Just came in 8 minutes ago...:)
 » 7 years ago, # |   +5 Nice problem and I think the main algorithm of the problem D in Div 1 may appeared at CodeForces early.
 » 7 years ago, # |   0 Problems C div 1: in each unit time interval we can move x length units which x<=d or x=d? Can anyone help me?
•  » » 7 years ago, # ^ | ← Rev. 2 →   +11 in problem statement:You can move up to d length unitsthis means x<=d (up to == at most).but if the problem statement said "exactly d units" this means x=d
•  » » » 7 years ago, # ^ |   0 Thank you!
 » 7 years ago, # |   +4 in div1 A whats wrong in logic of pairing largest kangaroo with the largest kangaroo possible
•  » » 7 years ago, # ^ |   +3 Take the following example: n: 4 s: 1 1 4 8 According to your logic you pair 8 with 4 (8 = largest kangaroo, 4 = largest possible kangaroo that fits 8). Thus you will get 3 visible kangaroos at the end.The correct answer is 2 (visible kangaroos). You pair 4 with 1 and 8 with 1.
 » 7 years ago, # |   0 I have posted this exact same comment on the Editorial Blog of this round. Since I did not get any reply, I thought if I post my thoughts here and can find some help :)Can someone illustrate the idea of Watching Fireworks is Fun more clearly. I have read DEGwer's editorial and tried to understand his code. But I can't figure out what is this part doing // Line 32-34 of the code linked in the editorial for (lint j = 1; j <= interval; j++){ while (dq.size() && dp[1 - p][dq[dq.size() - 1]] <= dp[1 - p][(int)j]) dq.pop_back(); dq.push_back((int)j); } if i is the order of firework ( i Can be Maximum m) and j is my position on main road ( At most 150000 positions)As far I understand , if I am at State DP[i][j] I need to find out the maximum value between the interval from DP[ 1-i ][ j-x ] through DP[ 1-i ][ j ] to DP[ 1-i ][ j+x ]Where x=available time(i.e t[ i ]- t[ i-1 ]) * D i.e DEGwer represents x as intervalBut in the code segment I blocked above, DEGwer have started the for loop from 1 to interval.  for (lint j = 1; j <= interval; j++) But shouldn't it iterate through like for(int m=j-interval;m<=j+interval;m++) please explain what I am thinking wrong. Thanks in advance :)