### Dalgerok's blog

By Dalgerok, history, 13 months ago, translation, ,

Hi, Codeforces!

Codeforces Round #553 (Div. 2) will be held on Apr/18/2019 18:35 (Moscow time). Round will be rated for second division (rating below 2100). As usual, participants from the first division can participate in the contest out of competition.

My gratitude to arsijo and KAN for coordinating the round, Markellonchik (special thanks for the help in preparing one of the tasks), mohammedehab2002, Jeel_Vaishnav for testing, and also 300iq for the idea and preparation of one of the tasks, aleks5d and isaf27 for testing it, and of course MikeMirzayanov for Codeforces and Polygon systems.

In this round you will help the residents of the Kingdom of Kremland. I strongly recommend you to read the statements of ALL tasks (and of course, try to solve them).

Good luck!

UPD: Scoring distribution: 500-750-1250-1750-2250-2750.

UPD: Editorial

UPD: Thank you for your participation in this round! Congratulations to the winners!

Div. 2

• +260

 » 13 months ago, # |   -20 how much problems are required to solve in division 2 to get expert rating
•  » » 13 months ago, # ^ |   -34 You should solve ABC in 30 minutes
•  » » » 13 months ago, # ^ |   -13 thanks man
•  » » » 13 months ago, # ^ |   -13 N what bout specialist? What should be done 2 reach this rating?
•  » » » » 13 months ago, # ^ |   -12 i think that you should solve A,B very fast, or A,B,C a bit fast.
•  » » 13 months ago, # ^ |   +76 I think solving ABC super fast is not primary goal to go 1600+, instead try to solve ABCD in 2 hours.
 » 13 months ago, # | ← Rev. 2 →   -13 Ok
 » 13 months ago, # |   +15 Those feelings when you wait for the contests to read the tasks and not solve them
 » 13 months ago, # |   +19 Sorry if my question is silly, will it be rated for Div3 participants as well?
•  » » 13 months ago, # ^ |   +2 Of course!
•  » » » 13 months ago, # ^ |   +1 Thanks! :)
•  » » » » 13 months ago, # ^ |   +18 I wish you good luck! You did well yesterday, in your first contest!
•  » » » » » 13 months ago, # ^ |   0 Thanks, it was a good contest!
 » 13 months ago, # |   0 6 problems?
 » 13 months ago, # |   -26 Can div3 pupils improve their rating by solving A problem?
•  » » 13 months ago, # ^ |   0 Depends on how fast you are, where in pupil range you are, and of course how hard the tasks are, but generally I don't think so. You may try solving at least A and B, which I think in most case will give rating improvements. BTW. I don't think that there is a big gap between Div.2 AB and Div.3 AB. Difficulty gap between 2 different div2 contests are actually larger (in my opinion, but problem rating data also kina shows similar results.)
 » 13 months ago, # |   0 I strongly recommend you to read the statements of ALL tasks (and of course, try to solve them)I have seen a similar thing here. I will read all the tasks only if you say so. :P
 » 13 months ago, # |   +60 But still, any updates on 0 IQ Challenge?:)
 » 13 months ago, # |   0 flood of contests, thanks MikeMirzayanov
 » 13 months ago, # | ← Rev. 2 →   -23 I wish positive rating for every participant :)
•  » » 13 months ago, # ^ |   +33 This is not possible :)
 » 13 months ago, # | ← Rev. 2 →   -27 i hope to got an expert grade after this contest!
 » 13 months ago, # |   0 How much should I solve 2 get specialist rating?
•  » » 13 months ago, # ^ |   +3 maybe 3? i guess
 » 13 months ago, # |   +11 Will (Forethought Future Cup — Elimination Round) be a rated contest? Can any one tell me, please.
•  » » 13 months ago, # ^ |   +54 Yes.
 » 13 months ago, # |   +1 Expecting this round to be full of awesome questions with strong pretests!!!
•  » » 13 months ago, # ^ |   0 with good pretests uninteresting hack))
 » 13 months ago, # | ← Rev. 2 →   +8 Hear This before contest and you will RISE by 100
 » 13 months ago, # |   0 Well good luck for today's contest..Its time to sit back and watch Game of Thrones..
 » 13 months ago, # |   -6 Score distribution?
 » 13 months ago, # |   0 No interactive problem today :(
 » 13 months ago, # |   0 No extra registration?
 » 13 months ago, # |   +5 I am not able to submit my codes. I am getting an error message saying "You have already submitted the exact code before" even when I haven't made a single submission.
•  » » 13 months ago, # ^ |   0 add anything... like a space or anything to that code somewhere
•  » » » 13 months ago, # ^ |   0 I tried changing the codes, it still gives the same message.
 » 13 months ago, # |   0 Can i register now after the contest started?
 » 13 months ago, # |   0 Solution for D?
•  » » 13 months ago, # ^ | ← Rev. 3 →   +5 Sort by $(a_{i}-b_{i})$
•  » » » 13 months ago, # ^ |   0 Got this algorithm right away, but pretest 12 wouldn't run fast enough with my Python code... Tweaked it for efficiency as much as I could, and eventually it got past 12 but gave me a time limit error on 13.
•  » » » » 13 months ago, # ^ | ← Rev. 2 →   0 You have to select Python 3 instead of PyPy 3 as the language
•  » » » » » 13 months ago, # ^ |   0 Ironically, I was using PyPy because I thought it was faster...
•  » » » » » » 13 months ago, # ^ |   0 And yup, works perfectly when submitted in Python 3. Sigh.
•  » » » » » » » 13 months ago, # ^ |   0 It is just the input that is slow with PyPy. You can get it accepted if you take care of that: 52988802
•  » » 13 months ago, # ^ |   +21 Notice that $a_i(j-1)+b_i(n-j)=j(a_i-b_i) + n b_i - a_i$. So, what matters is the value $a_i - b_i$.
•  » » » 13 months ago, # ^ |   0 :( Late
•  » » 13 months ago, # ^ |   +9 Dissatisfaction be rewritten as $j(a_i-b_i)+b_in-a_i$. Thus, we are trying to order $i$'s to minimize the sum of $j(a_i-b_i)$. Just sort them in decreasing order of $a_i-b_i$ and that should be the minimum. You can use an exchange argument to prove it.
•  » » 13 months ago, # ^ |   0 https://pastebin.com/tmHW66YhHere's my solution, if you want the code, but if you want an explanation, I can give that as well.Take this input: 10 5 10 12 4 31 45 20 55 30 17 29 30 41 32 7 1 5 5 3 15The correct order from left to right is sorting from largest to smallest in terms of Ai-Bi: 30 17 (30-17 = 13) 41 32 (9) 12 4 (8) 7 1 (6) 5 5 (0) 29 30 (-1) 5 10 (-5) 3 15 (-12) 31 45 (-14) 20 55 (-35)If in doubt, read the problem statement and bring out your calculator.
 » 13 months ago, # |   +18 For contests like these, you should get my script which sorts problems by number of submissions :) Here
 » 13 months ago, # |   0 Can someone give me a hint on D?
•  » » 13 months ago, # ^ |   0 Hint: What's the formula for number of components in a tree?
•  » » » 13 months ago, # ^ |   +8 Ah, that's a hint for E actually. :D
•  » » » » 13 months ago, # ^ |   +6 I was wondering...
•  » » 13 months ago, # ^ |   +3 Expand the formula for dissatisfaction
•  » » 13 months ago, # ^ |   +6 ans = sum (a[i]*(i-1) + b[i]*(n-i)) for i=1 to n = sum ((a[i]-b[i])*(i-1) + b[i]*(n-1)) Now to minimize ans you should minimize (a[i]-b[i])*(i-1) So sort (a[i]-b[i]) in reverse order. 
•  » » » 13 months ago, # ^ |   +1 Got it. Thanks
•  » » 13 months ago, # ^ |   +1 since ans = summation(a[i]*j + b[i]*(n-j)),so we have to assign positions such that for each i if a[i] > b[i] start filling it from left and from right otherwise ,but since j factor is there ,so more the (a[i]-b[i]),put it most left..
 » 13 months ago, # |   +7 Nice problems!
 » 13 months ago, # |   0 Any hint for E?
•  » » 13 months ago, # ^ | ← Rev. 2 →   +3 Hint: What's the formula for number of components in a forest?
•  » » » 13 months ago, # ^ |   +8 idk
•  » » » » 13 months ago, # ^ |   +5 Number of Vertices — Number of Edges
•  » » » 13 months ago, # ^ |   +27 a forest with V vertices and E edges has V-E components?
•  » » 13 months ago, # ^ |   +25 First Compress the array by merging consecutive indices with same value in one component. Consider $dp[r] = \sum_{l = 1}^{r} f(l, r)$. Now, we have $dp[r] = (\text{number of elements with value r}) * r + dp[i - 1] - \text{number of edges that occur when we add elements with value r}$. the last term can be found by going through elements with value r, and checking its neighbours, If the neighbour's value is less than r, say x, it means for l <= x there will be an added edge. hence you add x to the last term in dp.
•  » » 13 months ago, # ^ |   +8 Let's consider the starting of any component. Let it start at position i. Now, this is a starting position iff a[i — 1] does not belong to the range [l, r] and a[i] belongs to the range [l, r]. So we'll calculate the number of ranges [l, r] s.t. a[i] is inside this range and a[i — 1] is outside this range. The sum of the number of possible ranges over all i will give you the answer.
 » 13 months ago, # |   0 Hacks for A and B?
•  » » 13 months ago, # ^ |   +2 I did one successful hacking attempt in B, and the testcase was: 2 2 // H, W 8 9 // A[1][1], A[1][2] 8 8 // A[2][1], A[2][2] The only possible answer is TAK: C = [2, 1], but I found a submission which is assuming that $C$ is non-decreasing, so I could hack this solution.
 » 13 months ago, # |   +3 what's about test 4 in C?
 » 13 months ago, # |   +5 strictly greater than zero or greater than zero, same things?
•  » » 13 months ago, # ^ |   0 Yup
 » 13 months ago, # |   -8 Got wrecked on problem C because of double precision in C++. I used double everywhere but when I switch to long double it gives another result. Both results are remarkably close to the expected answer on pretest 3. Can someone help me on this one ?On pretest 3: - Expected answer: 761141116 - Answer I get using double everywhere: 761034963 - Answer I get using long double everywhere: 761141203
•  » » 13 months ago, # ^ |   0 Why are you using doubles? Just use ints/long longs and modulo 1e9+7 as you go.
•  » » » 13 months ago, # ^ |   0 I added the results by "chunks" like it was explained in the problem, so the chunks could get over the maximum long long value in C++
•  » » » » 13 months ago, # ^ |   0 Yeah but just calculate the chunks as their values mod 1e9+7...
•  » » 13 months ago, # ^ |   0 You should not be using floating point numbers in a problem like this, where the exact answer can be found using integers.Solution: It is enough to calculate the sum of values in the range [1..M], because then the sum of values in the range [L..R] can be found doing a subtraction. To find it, we can recreate the process in which numbers are written in the blackboard to find how many odd and even numbers where added. Something like this: int to_add=1, remaining=M, numodd=0, numeven=0; while (M > 0) { // Complexity log(M) because you are substracting powers of 2 if (remaining >= to_add) then sum to numodd or numeven; else put the rest in numodd or numeven; to_add*=2; } Once you know how many odd and even numbers are the in the black board, you can calculate two sums of the form 1+3+5+... and 2+4+6..., which are easy arithmetic sums (use a formula). In addition, remember that you must perform the operations modulo 10^9+7.Hope it helps.
•  » » » 13 months ago, # ^ |   0 Thanks for the answer. I basically tried this implementation, but I thought that sum_to_numodd could exceed the maximum long long value if r is very big. Looks like I was wrong
•  » » » » 13 months ago, # ^ |   0 Well, think about it. The number r fits in a long long, and r = num_odd+num_even (all positive), so those fit as well.
•  » » » » » 13 months ago, # ^ | ← Rev. 2 →   0 I'm afraid I don't understand. Surely r fits in a long long, but the sum of all even integers from 2 to r doesn't. That's why I think I needed doubleedit: well it turns out I have not done your implementation. Sorry for the misunderstanding
•  » » » » » » 13 months ago, # ^ |   0 Ok, fine then.Just to clarify in case someone else is also confused: num_odd is the number of odd numbers written in the board, not their sum. Their sum can be easily calculated using the formula for the sum of an arithmetic progression.
 » 13 months ago, # | ← Rev. 2 →   +32 After reading B:Me: OK, randomized algo should workInner Me: But there's a possibility it will failMe: Very low thoughInner Me: So, you are saying you never had something happened to you that was totally unexpected?Me: Ok Ok. I will write a dp solution.Conclusion: Got Hacked 2 minutes before the end of the contest. Then resubmitted a randomized solution anyway because there was not enough time for debugging
 » 13 months ago, # |   +6 Approach for E ?
•  » » 13 months ago, # ^ | ← Rev. 2 →   0 I haven't solved it But I have some idea with stack、、wait for help too.
•  » » 13 months ago, # ^ | ← Rev. 2 →   +9 Number of connected components $f(l, r) = 1 + (\text{number of cut edges}) - (\text{number of cut vertices})$You can calculate total number of cut edges and cut vertices in $O(n)$ each.
•  » » » 13 months ago, # ^ |   0 thx
•  » » » 13 months ago, # ^ |   0 can you please elaborate a little more?
•  » » » » 13 months ago, # ^ | ← Rev. 10 →   +6 $\sum_{l=1}^{n} \sum_{r=l}^{n} f(l,r) = \sum_{l=1}^{n} \sum_{r=l}^{n} (1 + (\text{number of cut edges}) - (\text{number of cut vertices}))$ $= \frac{n(n+1)}{2} + \sum_{l=1}^{n} \sum_{r=l}^{n} ((\text{number of cut edges}) - (\text{number of cut vertices}))$ $= \frac{n(n+1)}{2} + \sum_{\text{for each edge}} (\text{how many cut occurred on this edge?}) - \sum_{\text{for each vertex}} (\text{how many cut occurred on this vertex?})$Let $p = \text{min}(a_{i}, a_{i+1}), q = \text{max}(a_{i}, a_{i+1})$When $p \lt l$ or $r \lt q$ then the edge will be cut.Cut count of edge $i$ ~ $i+1$ is equivalent to $\frac{1}{2}((n-p)(n-p+1) + (q-1)q - (q-p-1)(q-p))$When $l \le r \lt a_{i}$ or $a_{i} \lt l \le r$ then the vertex will be cut.Cut count of vertex $i$ is equivalent to $\frac{1}{2}((a_{i}(a_{i}-1) + (n-a_{i})(n-a_{i}+1))$
•  » » » » » 13 months ago, # ^ |   +3 A simpler way of thinking about this problem: for each element a[i] count the number of ways to choose (l, r), such that a[i] is the last element in its component.
•  » » » » » 13 months ago, # ^ |   0 if n=3 S(l=1 to 3)S(r=l to 3)= 1+2+3+2+3+3 How you derive n*(n+1)/2 If im wrong, correct me.
•  » » » » » » 13 months ago, # ^ | ← Rev. 2 →   0 $\sum_{l=1}^{n} \sum_{r=l}^{n} 1 = \sum_{l=1}^{n} (n-l+1) = n^{2} - \frac{1}{2}n(n+1) + n = \frac{n(n+1)}{2}$It's $1$, not $l$.
 » 13 months ago, # |   0 Any ideas about Test Case 8 in problem B?
 » 13 months ago, # |   -14 very poor pretests
 » 13 months ago, # |   0 How to solve div2 B? what I did is that I maintained a cnt[] array and I didn't registered a number if is has been entered more than once. After this I took maximum element from each row and computed the answer. (I now know this approach is wrong) Any additions here?
•  » » 13 months ago, # ^ |   +1 The idea look like dpdp[510][1024] dp[i][j] means The preceding i-line scheme for forming number “j”and dp[510][1023] can be optimized to dp[1024]
•  » » 13 months ago, # ^ |   +2 Basically if a row contains at least two different numbers then there is a solution. If not any row contains two differents numbers, then just compute bitwise xor of a_(i,1) for i in range (0,n). If it's 0 then the answer is NIE, else you have your solution
•  » » » 13 months ago, # ^ | ← Rev. 3 →   0 Oh no... it really was THAT simple!!! Thanks, brurrito.
•  » » 13 months ago, # ^ | ← Rev. 6 →   0 observation: if a != b, a ^ b > 0 (in this problem i used bruteforce).fix a row that has > 1 unique value (if there's any, but if none than you can pick any row).let k be the fixed row, after that you xor any value of a[i][0] excluding that row (that is a[0][0] ^ a[1][0] ^ ... ^ a[n — 1][0] ^ a[k][0]), let the value val.now you try all possible value x in this row k, if any val ^ x > 0, then you found the answer (n — 1 column 1 and 1 column in the fixed row).My submission: 52983517
•  » » 13 months ago, # ^ |   0 Carry a cell from each row, as your wish... if the xor of all values equal 0, then just try change any of those values from any row..if it is not possible, then NIE
 » 13 months ago, # |   0 Any tips for B?
•  » » 13 months ago, # ^ |   +4 If x is not y, then (x xor a) is not (y xor a).
•  » » 13 months ago, # ^ |   +2 Randomly assign one number from each row. If the xor of all the assigned numbers is greater than 0,the problem ends there, else changing any one number among the chosen ones will change the xor. Try replacing each number in the matrix and when the xor is not equal to zero, that's one solution
•  » » » 13 months ago, # ^ |   0 I'm sorry. I didn't realize you asked for tips and not the solution
•  » » 13 months ago, # ^ |   0 Well, you can consider each bit separately (there are $\leqslant 10$ bits). Now for $\operatorname{xor}$ to be non-zero you need an odd number of $1$'s. If the answer is 'yes' for at least one bit, then you have found a solution.
•  » » 13 months ago, # ^ |   0 Look at it as a dynamic programming problem. N <= 500, A_{i,j} <= 1023 Try them all and save the answer. Spoiler - dp statesThe dp states are : dp[row][current_number] Time complexity and my sub O(N^2 * MAXA_{i,j]) My sub: 52973863I don' t know how to use latex or markdown in comments, sorry for bad formatting.
•  » » » 13 months ago, # ^ |   0 thanks for your help!
•  » » 13 months ago, # ^ |   0 Carry a cell from each row, as your wish... if the xor of all values equal 0, then just try change any of those values from any row..if it is not possible, then NIE
 » 13 months ago, # |   +2 What is the difference between greater than zero & strictly greater than zero ?
 » 13 months ago, # | ← Rev. 3 →   +8 My solution for pE was :First, calculate the numbers of the interval that each vertex will leave in the tree.Second, minus the numbers of the interval for each pair (i,i+1) that there is an edge between them.  for(int i = 1; i <= n; i++){ cin >> a[i]; ans += a[i]*(n-a[i]+1); } for(int i = 1; i < n; i++){ int mn = min(a[i],a[i+1]),mx = max(a[i],a[i+1]); ans -= mn*(n-mx+1); } 
 » 13 months ago, # |   -12 Very very weak pretests on problem B.
•  » » 13 months ago, # ^ |   +4 Could I add another "very"?My solution was 'sorting' the array and I was printing the modified indices and somehow that passed the pretests. In, normal occasions this solution should not even pass the samples.
 » 13 months ago, # |   0 How to solve E ?
•  » » 13 months ago, # ^ |   0
 » 13 months ago, # |   -47 One of the worst contests IMO. Very Unbalanced.
•  » » 13 months ago, # ^ |   +9 Agree that they should have swapped C and D instead, but I think many of the problems require nice insight (like B, D and E).
•  » » » 13 months ago, # ^ |   +1 I think this contest was better for the higher rated participants in Div 2. But for people like me and below, it was hard to get that insight.
 » 13 months ago, # |   -30 Ok, i don't want to be "that guy", but someone has to say it. I think that there were at least 2 coders who participated in this contest from the same account. And yes, i am referring to the user square1001. Time of submissions B and D are < 3 min , and between C and E is only 5 min. While i think that it is possible for someone to get the idea for them in a few minutes + reading the statement, i really doubt that they can code like this. And anyway, if you are that good, why take order B,D,C,E? Why not straight E,D,C,B? Also, coding styles seems to differ, so yeah, definitely something to look into, beloved admins.
•  » » 13 months ago, # ^ | ← Rev. 2 →   +119 Please do not doubt — I am pretty surprised and happy that I won this round, and I was lucky that ecnerwala participated 30 minutes after the contest begins (if he participated from first, I think I lost). So, why did I take order B, D, C, E, A, F? I did pretty strategical. - First, opened problem B because I thought that opening problem B is lighter for servers than opening problem A. Then solved in ~3 minutes. It was not so difficult. - Second, opened problem C. But updating standings every ten seconds, I found out that problem D is already solved by someone! Hence, I immediately moved to problem D. I have came up with the solution in ~15 seconds, and the implementation was easy, so I solved in like ~2.5 minutes. - Then, re-thought problem C. Implementation was not so difficult, but my code bugged so it took ~6 minutes to solve. - In this time, the solver of E existed, so I moved to problem E. I had came up with the idea of "we should only care about difference in position $i$ and $i+1$ (+ two sides)", 1 seconds after I read the problem statement completely. The implementation was easy, so I could solve in 5 minutes. - Then, I moved A and solved easily. I had a pretty difficult time in solving F, because my matrix library is really slow (but the TL is 1 second), so I coded without using own library. I am very happy to win in such contest, in contrast to last contest taking 30 minutes in easy Div.2 B. P.S. You said that the coding style differs. What pair of problems are you pointing?
•  » » 13 months ago, # ^ | ← Rev. 2 →   0 I think code for D can be written in 1 min. And if you get the idea straight then it's an easy problem. Just read A. Statement and so many conditions, but still people have submitted in <3 min. Where i found A hard than D to code and understand. So writing code in 2-3 min for D is fine. Even problem E is too easier, if you know the logic. Just count of cut edges and cut vertices. Thinking may take 3-4 minutes. But code can be definitely written in 1 min. So I don't see any kind of cheating. You just go through other good coders' submissions, most of them have solved D, E in <= 5 min.
 » 13 months ago, # |   +3 Got my first successfully hack and first system test failed on PB lol
 » 13 months ago, # | ← Rev. 2 →   0 What was your approach on last problem F?
•  » » 13 months ago, # ^ | ← Rev. 2 →   0 You can change the problem into weighted graph that has $4Hn$ vertices and up to $16 \times 4Hn$ vertices. Use binary jump (I don't exactly know the formal name of these kind of techniques) to calculate after $k$ moves in this graph.For your information, $nHr = n+r-1Cr$.I couldn't code my idea in last 20 minutes.
•  » » 13 months ago, # ^ | ← Rev. 2 →   -7 not)) this is just boolshit))
•  » » » 13 months ago, # ^ |   0 Your approach is clean and compact!
•  » » 13 months ago, # ^ |   +22 Let $z$ be the number of zeroes in the array. Consider the block of first $z$ bits: array is sorted iff it's all zero.Let $dp[i][u]$ be the probabilty that after $i$ steps we will have $u$ ones in the first $z$ bits. Then the answer will be $dp[k][0]$.Starting from $dp[i][u]$ there are three possibilities after the next step: $u$ didn't change. Either we swapped something inside a block (there are $z \cdot (z - 1) / 2 + (n - z) \cdot (n - z - 1) / 2$ ways to do that), or we took same bits from different blocks: $u \cdot (n - z - u)$ ways to take two ones and $(z - u) \cdot u$ ways to take two zeroes. $u$ increased by one. This can only happen if we took a $0$ from the first block and a $1$ from the second. There are $(z - u) \cdot (n - z - u)$ ways to do that. $u$ decreased by one. Then we took $1$ from the first block and $0$ from the second. There are $u^2$ ways to do that. You can easily change the calculation of this DP to backward and then use matrix exponentiation.
 » 13 months ago, # |   0 how to solve B?
•  » » 13 months ago, # ^ |   +3 Carry a cell from each row, as your wish... if the xor of all values equal 0, then just try change any of those values from any row..if it is not possible, then NIE
 » 13 months ago, # |   +3 Such a fast editorial. Nice!!
 » 13 months ago, # |   +3 Everything so fast...system testing + editorial + rating update...
 » 13 months ago, # | ← Rev. 3 →   +9 Finally reached Candidate Master. It's sad that I submitted my contest proposal when I was Expert.. But whatever, I am speechless and so happy.
 » 13 months ago, # |   0 the problem C can scare, but in fact easy, the most difficult, thing is to keep track of the overflow, but the python decides everything))https://codeforces.com/contest/1151/submission/52983378
 » 13 months ago, # |   0 Any hint about C ?
•  » » 13 months ago, # ^ |   0 If you want the whole solution, you can read the editorial. If you just want a hint, try to think of a formula by which you can solve this. It's similar to calculating the sum of the first n numbers, you just have to change it a little bit. :)
 » 13 months ago, # |   +10 And the statement, I strongly recommend you to read the statements of ALL tasks (and of course, try to solve them) makes sense :P.
 » 13 months ago, # |   0 Spent way too much time on observing patterns to arrive at an $O(\log{N})$ solution. The excitement of reading a math problem had got the best of me.
 » 13 months ago, # |   +3 order of this contest should be A,D,C,B,E,F
•  » » 13 months ago, # ^ |   +7 I can offer other order A,D,B,C,F,E
•  » » » 13 months ago, # ^ |   0 I found c easier than b,b was implementation heavy
 » 13 months ago, # |   0 I got a message that says my submission 52964771 coincides with sandrik398631‘s 52963443. They look really similar. But the problem A is too simple and my coding style is somewhat similar to sandrik398631. How can I appeal? All my submissions are skipped. Is it because of of this?
 » 13 months ago, # |   0 Can B solved by DP?
•  » » 13 months ago, # ^ |   +2 Yes, B can be solved by DP. You can maintain a DP of size 510*1024, Here dp[i][j], i is the row number and j is the xor of numbers. So, all dp[i][j] values will be 1, if we can have xor j at an ith row, otherwise, the value will be 0. If the value is non zero, store the parent i.e. the element in (i-1)th row which xor with current element will give the xor j.Please look at code for more clear representation.
•  » » » 13 months ago, # ^ |   0 Thanks shreyansh08
 » 13 months ago, # | ← Rev. 3 →   +1 I have done following in problem C. Function calculates the sum in set till number n.ev — next even sequence start od — next odd sequence startthen for each iteration, I calculate start and end of that sequence and calculate their sum by AP. It is giving wrong answer on test case 1 1e18. Is there an overflow ? I cannot find the bug in function calc.code link CODE#include #include #include using namespace std; #include #include using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; // s.order_of_key(x); // gives order of x in the set #define For(i,x,n) for(long long i=x;i>l>>r; cout<<(calc(r)-calc(l-1)+MOD)%MOD; //cout<<"\nTime used = "<(clock())/(CLOCKS_PER_SEC)<<"s"< hm; ll i; for(i=2 ; i*i<=15000002 ; i++) if(isprime[i]==0){ for(ll j=2*i ; j<=15000001 ; j+= i) if(isprime[j]==0) isprime[j]=i; isprime[i]=i; hm[i] = cc; cc++; } for( ; i<15000002 ; i++) if(isprime[i]==0) isprime[i]=i,hm[i]=cc,cc++; } ll choose(ll n,ll k) { if(k==0) return 1; return (n* choose(n-1,k-1))/k; } void showArray(ll a[], ll n){ For(i,0,n){ cout< eps && fabs(y) > eps) { if (x > y) x -= floor(x / y) * y; else y -= floor(y / x) * x; } return x + y; } ll power(ll x,ll n) { if(n==0) return 1; else if(n%2 == 0) //n is even return (power((x*x)%MOD,n/2))%MOD; else //n is bal return (x*power((x*x)%MOD,(n-1)/2))%MOD; } ll power1(ll x,ll n) { ll num = 1; For(i,0,n){ num = (num*x)%MOD; } return num; } 
 » 13 months ago, # |   0 I have written a C solution that I would consider well documented and can be easily understood by anyone. It might not be the shortest or cleverest solution, but I believe it's nice to have it this way. Please comment where this solution can be improved. Thanks in advance.
 » 13 months ago, # | ← Rev. 2 →   +5 I noticed that a lot of D solution only sort using the key a-b, and I wonder why it is acceptable. Rearrangement of the dissatisfaction value $a_i(j-1) + b_i(n-j)$ gives $(j-1)(a_i-b_i) + b_i(n-1)$. To minimize the sum of all dissatisfaction, we would assign small $j$'s with large $(a_i-b_i)$, when the position of the student does not affect the term $b_i(n-1)$. What I does not understand is that when various students share the same $(a_i-b_i)$, the value of $b_i$ itself should make a difference. However, it doesn't seem to be the case. Am I missing something?EDIT: After thinking more carefully, I realize that it really doesn't matter. Their dissatisfaction value would be different, but we are not trying to arrange them in order of dissatisfaction anyway.
 » 13 months ago, # |   0 Congratulations to the winner！
 » 13 months ago, # |   0 The link to the editorial redirects to home page. Anyone else facing this issue?
 » 7 months ago, # |   0 Can someone make links to the editorial and to the contest announcement in the contest page? They do not exist for me here: https://codeforces.com/contest/1151