Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

By pikmike, 14 months ago, translation, ,

Hello Codeforces!

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given 7 problems and 2 hours to solve them.

The problems were invented and prepared by Roman Roms Glazov, Adilbek adedalic Dalabaev, Vladimir Vovuh Petrov, Ivan BledDest Androsov, Maksim Ne0n25 Mescheryakov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.

Good luck to all participants!

Our friends at Harbour.Space also have a message for you:

Hello Codeforces!

We are collaborating with an external sponsor who is offering a unique scholarship opportunity for women who want to study Cybersecurity or Fintech, both for Bachelors and Masters level.

The scholarship includes:

• An up to \$10,000, one-time financial award, paid to the University
• An all-expenses-paid trip to the EMEA Summit 28-30 October, 2019 in Berlin
• A Cybersecurity professional to serve as an industry mentor

Apply before May 30th and Harbour.Space will also consider you for a scholarship from our own funds.

Don't miss this chance to study with us in Barcelona!

APPLY HERE→

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
2 mnbvmar 7 183
3 I_love_Tanya_Romanova 6 119
4 Farhod_Farmon 6 124
5 xiaowuc1 6 142

Congratulations to the best hackers:

Rank Competitor Hack Count
1 algmyr 57:-1
2 mnbvmar 16:-2
3 xavier_cai 11:-1
4 halyavin 10:-3
5 avm 7
291 successful hacks and 306 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A Dalgerok 0:01
B Farhod_Farmon 0:05
C DieOrBreakout 0:04
D nuip 0:10
E Farhod_Farmon 0:23
F ugly2333 0:13
G Dukkha 0:57

UPD: Editorial is out

• +92

 » 14 months ago, # |   +1 Will there be a scholarship for men also?
•  » » 14 months ago, # ^ |   +96 No, but if you tell them you identify as a female, you'll get in.
•  » » » 14 months ago, # ^ |   +18 too edgy
•  » » » » 14 months ago, # ^ |   0 everything is too edgy for you because you are geniosity
•  » » » » » 14 months ago, # ^ |   +2 wtmoo
•  » » » 14 months ago, # ^ |   +32 This is now possible if you're using the new Snapchat filter
•  » » 14 months ago, # ^ |   +32 Hey ElegantSound ! We have scholarships for both men and women and we post about them regularly on Codeforces! If you are interested in one, you can apply on our website! Everyone applying to the university is taken into consideration for a scholarship and no separate application is required.
 » 14 months ago, # | ← Rev. 2 →   +32 Is he considered as a woman ?
•  » » 14 months ago, # ^ |   0 too funny
 » 14 months ago, # |   +231 Educational round logic :D
•  » » 14 months ago, # ^ | ← Rev. 3 →   -60 good luck everyone
 » 14 months ago, # | ← Rev. 2 →   -12 Seems this round will be started before publishing division 3 rating change xD
 » 14 months ago, # |   +11 Rmind:Educational round correspond the third category in System problem something and i hope Reconciliation to All Participants
 » 14 months ago, # |   -28 wait this round is dedicated to women? Then I guess its a div 4 guys shit.
•  » » 14 months ago, # ^ |   0 This is why you're blue xD
•  » » » 14 months ago, # ^ |   -19 ?xDxD what you mean??xDxDxDxD=))
 » 14 months ago, # |   0 Good luck to everyone!
 » 14 months ago, # |   0 I have no experience of rating adding in edu round :(
 » 14 months ago, # |   +11 hope to become an expert = =
•  » » 14 months ago, # ^ |   0 good luck
•  » » » 14 months ago, # ^ |   +7 thx, but i may have lost in speed.. TAT
 » 14 months ago, # |   -15 What's the difference between Div 3 Rounds and Educational Rounds besides the rating limit?
•  » » 14 months ago, # ^ |   +8 Problem difficulty. Div. 3 problems are generally easier than Educational rounds.
•  » » » 14 months ago, # ^ |   -38 I do not agree with you my friend.
•  » » » » 14 months ago, # ^ |   +6 I do not agree with you my friend.
•  » » » » 14 months ago, # ^ |   +8 Div 3 are full of greedys!
•  » » » » » 14 months ago, # ^ |   0 That's accurate, no doubt about it, but it doesn't mean dificulty in Div 3 problems is lower, at least the way I perceive it.
•  » » » » » » 14 months ago, # ^ | ← Rev. 2 →   0 You have compete in so much CF rounds . If we take into account what I see is you have solve max (3) problems in Educational rounds sometimes (1) and if we look into Div 3 most of the time you solve (4) problems.I am not saying that div3 rounds are so easy but it is easier than Educational rounds and you prove most of the time by solving more problems in Div3 if we compare with educational.Rest is up to you.:P
 » 14 months ago, # |   +8 Typo perhaps? Paid by the University not to the.
 » 14 months ago, # |   0 I have submitted for B around 10 times it says idleness limit exceeded please help
•  » » 14 months ago, # ^ |   0 flush the print. You can read the linked page, given in problem.
•  » » » 14 months ago, # ^ |   +1 Why were you guys here during the contest, lol?
•  » » » » 14 months ago, # ^ |   +3 I stuck at C so was taking a break. Still trying to understand why it is timing out. Perhaps it would be better if I jumped to D instead of coming here :)
•  » » » » » 14 months ago, # ^ |   +1 Are you using Union Find?
•  » » » » » » 14 months ago, # ^ |   0 I was using DSU with weighted Union Find. Got WA though :(
•  » » » » » » » 14 months ago, # ^ |   0 Why would you need weighted?
•  » » » » » » 14 months ago, # ^ |   0 Kinda, I created disjoint sets and then calculated connected components. Worked fast with my random N=500k test. Here is the solution.
•  » » » » » » » 14 months ago, # ^ |   0 Hmm. Python :/
•  » » » » » » » » 14 months ago, # ^ |   0 It looks like my solution has a problem with cycles. I created a big sample, when I set M to 20000 it returns result in 0.2 secs but when set to 30000 it loops forever. let me convert it to a proper Union Find.
•  » » » 14 months ago, # ^ |   0 Can you tell what i did wrong in this code 54197918
•  » » » » 14 months ago, # ^ |   0 You're using flush after second cin, not sure it effects something but delete it. In you first query you're sending "? 1 1", that returning a[1]*a[1], you need to add sqrt of that value to v (first v.pb(x)). One more thing, your solution is too crowded for that problem. After finding first number you can easily find others with a simple approach.
 » 14 months ago, # |   +3 Any hint for E and F? I think F can be solved by divide and conquer, but I don't know if my idea is correct..
•  » » 14 months ago, # ^ |   +3 I think E is related to finding the inversions in the array but couldn't improve the time complexity from O(n^2)
•  » » » 14 months ago, # ^ |   0 You can use 2 pointers because it is monotonous. I used binary search and got WA on test 57 but not sure if the method is wrong or i have a bug.
•  » » 14 months ago, # ^ |   0 For E: Fix l, starting from 1 to x. The idea is similar to 2 pointers and you will need some precomputated arrays.
•  » » 14 months ago, # ^ | ← Rev. 2 →   +8 Precalculate p[x] = are numbers <= x sorted, s[x] = are numbers >= x sorted, l[x] = max number <= x, f[x] = min number >= x, you can check if (l, r) is good in O(1), just do binary search.
•  » » 14 months ago, # ^ |   +16 F is just counting the coefficient of each $b_i$. You can process the $b_i$'s in sorted order and use a BIT to efficiently count how many terms smaller than your current $b_i$ are in a range, and their contribution to the coefficient.
•  » » » 14 months ago, # ^ | ← Rev. 2 →   0 Actually there are $O(n^2)$ range pairs, and I got stuck on this ranges. I try to consider left range and right range separately, but I cannot figure out how to count that for each i efficiently.
•  » » » » 14 months ago, # ^ |   +29 Say you're processing the ranges containing $a_i$. These are $[l, r]$ with $l \le i \le r$. If $a_j < a_i$ and $j < i$ then you add $1$ to the coefficient for each of the ranges that contain $a_j$. The right endpoint doesn't matter, so for each right endpoint $a_j$ is contained in $j$ ranges, and the total contribution to the coefficient is $j \cdot (n - r + 1)$, the latter being the number of right endpoints. You can get a similar expression for $a_j < a_i$ and $j > i$. To query efficiently you can build a BIT that allows you to get the sum of $j$ for $a_j < a_i$ and $j < i$, and another one for the right side. Then when you finish processing an element, you add it to the BIT.
•  » » » » » 14 months ago, # ^ |   0 What 'BIT' refers to?
•  » » » » » » 14 months ago, # ^ |   +3
 » 14 months ago, # |   0 please anyone show his code for problem B in c++14 PLEASE...
•  » » 14 months ago, # ^ |   -6 Here you are: 54185189
•  » » 14 months ago, # ^ |   +3 code for BThe queries are a1*a2 a3*a4 a1*a3 a5*a5，It is possible to deduce a1 a2 a3 a4 from the first three queries and we got a5 by asking a5*a5, Then the array can be determined uniquely.
 » 14 months ago, # | ← Rev. 2 →   +2 Has someone's nlog^2n in E passed? I kept getting TLE on test 6. I binary searched the r for each l. Edit: Passed after I dropped a logn.
•  » » 14 months ago, # ^ |   0 I was thinking on similar lines but wasn't that n^2 logn? How fast do you test if a particular l,r is valid?
•  » » » 14 months ago, # ^ |   0 No that is not n^2logn. What you are thinking is to check all possible (l,r) pairs whether it gives non-ascending array or not. Correct idea would be to get minimum r (using bs and some preprocessing) for each possible l (1..n) and adding n-r to the ans.
•  » » » 14 months ago, # ^ |   0 No, what I did was to fix a particular l. Then calculate the first 'r' such that [l, r] is valid. Then added n — r + 1 to the answer. Check my code here. I maintained the max prefix and suffix till the array is sorted for calculation.
•  » » » » 13 months ago, # ^ |   0 your code is better than editorial.
•  » » » » » 13 months ago, # ^ |   0 Thank you!
 » 14 months ago, # |   0 How to solve B?
•  » » 14 months ago, # ^ | ← Rev. 3 →   +6 Check answer for $a_{1}$ and next 4 elements, $a_{1}$ is equal to GCD of query answers hacked
•  » » » 14 months ago, # ^ |   0 Why?
•  » » 14 months ago, # ^ |   +4 Ask four queries: a1*a2, a2*a3, a3*a4, a4*a5brute force all 6! = 720 permutations, and check if the it matches with the above.https://codeforces.com/contest/1167/submission/54187357
•  » » 14 months ago, # ^ |   0 Ask (a1, a2), (a2, a3), (a3, a4), (a4, a5). Since ai*aj are unique you can get first 5 values easily, and the remaining value is a6.
•  » » » 14 months ago, # ^ |   0 Any test cases which can be used as hacks?
 » 14 months ago, # | ← Rev. 2 →   0 Hello, I tried solving problem C and I was getting runtime error on test 3. I could not find the error, can someone help me please? Here is my code: http://codeforces.com/contest/1167/submission/54204878
•  » » 14 months ago, # ^ |   0 You are taking input in O(n^2) fashion. That won't work I guess.
•  » » » 14 months ago, # ^ |   0 I guess so, thanks
 » 14 months ago, # | ← Rev. 2 →   +1 What is test 57 on problem E?
•  » » 14 months ago, # ^ |   0 Test cases visible now
•  » » 14 months ago, # ^ |   0 10 1000000 404504 367531 741030 998953 180343 781888 161191 855804 689526 976695
 » 14 months ago, # |   +21 What's with the super tight bounds in F? My O(n log n) solution takes 1996/2000ms. 54195181Happy hacking :P
 » 14 months ago, # | ← Rev. 3 →   +1 My code WA test 1???? 54208002check the answer on CodeBlacks why this code Run on Codeforces get "WA" and this test example is test one !!!
 » 14 months ago, # |   0 The problem D inputs by "cin" will get "WA" ,replace "scanf" get "AC" ,why??
 » 14 months ago, # | ← Rev. 2 →   -20 among 8 div2 participants eho is better than me 7 of them are fake accounts. it is unfair lol i should be the 2nd, not 9th
 » 14 months ago, # |   0 [submission:54208002]This code "WA" test 1???
 » 14 months ago, # |   0 Is in problem E wrong to do binary search? Isn't it the same as 2 pointers?
 » 14 months ago, # |   0 What a pity! For E, cin/cout got a TLE while scanf/printf passed.
•  » » 14 months ago, # ^ |   +3 Input/Output speed is not a problem because I also used cin/cout in E and pased. You just need to add ios_base::sync_with_stdio(0) to make cin/cout as fast as scanf/printf.
•  » » » 14 months ago, # ^ |   +3 Thanks very much. Indeed, with sync_with_stdio(0) my solution passed. But it still has a gap with scanf/printf.For cin/cout with sync_with_stdio, it takes 1606 ms. While for scanf/printf, it takes 1278 ms.
•  » » » » 14 months ago, # ^ |   +1 Try using cin.tie(0); cout.tie(0) It is usually faster than scanf/printf
•  » » » » » 14 months ago, # ^ |   0 Thanks! But for this problem, it still takes 1578 ms, not as fast as scanf/printf.
•  » » » » » » 14 months ago, # ^ |   0 You can use "\n" instead endl
 » 14 months ago, # |   -15 C and D were easier than B.
 » 14 months ago, # |   0 Why did my solution to problem D gave TLE: codeRemoving stack and converting string to character array passed the pretest. Don't know why..
•  » » 14 months ago, # ^ | ← Rev. 2 →   +3 Because adding two strings is linear to their length. If you just push the char in the end is O(1). Changing it with += that equals to push_back it gives acc 54211273 (your sub with this change)
•  » » » 14 months ago, # ^ |   0 Oh I didn't knew abt it. Thanks :)
 » 14 months ago, # |   -21 Authors should have announced that there will be interactive problems in the contest beforehand.
•  » » 14 months ago, # ^ |   +9 Why?
•  » » » 14 months ago, # ^ |   0 Many of Division2 participants didn't have any idea about interactive problems (I am also one of them). Because usually div2 contests doesn't contain this type of problems. To know and learn about them all on a sudden in a running contest is taught and time consuming.
•  » » » » 14 months ago, # ^ |   +13 There is nothing to learn, interactive problems don't differ much from usual problems. My first interactive problem was on NEERC 2010, I had green level then but I solved it without any difficulties. I don't understand why so many people are afraid of interactive problems.
 » 14 months ago, # |   0 Any hacks available for problem (B) ?
 » 14 months ago, # | ← Rev. 2 →   0 Thank you creators for such cool problems. I really enjoyed it.
 » 14 months ago, # |   0 why this solution(54181282) is getting wrong answer on testcase 2?
•  » » 14 months ago, # ^ |   +6 Wrong output
•  » » 14 months ago, # ^ |   +9 The line producing the error is probably this:for(i=s.size()-11;i>=0;i--)s.size() returns an unsigned int and if s.size()<11, s.size()-11 will underflow and take a value of the order 2^32.
•  » » » 14 months ago, # ^ |   +3 Change s.size() to (int)s.size()
•  » » » » 14 months ago, # ^ |   0 thank you.
•  » » 14 months ago, # ^ |   0 For s with length less than 11
 » 14 months ago, # |   0 Is it possible to solve C with a method other than Union Find?
•  » » 14 months ago, # ^ |   +12 dfs
•  » » 14 months ago, # ^ |   0 use map.
 » 14 months ago, # |   0 https://codeforces.com/contest/1167/submission/54196574 Why Do I get TL ?
•  » » 14 months ago, # ^ |   0 It is Memory limit exceeded
 » 14 months ago, # |   0 Why was problem b hacked?
•  » » 14 months ago, # ^ |   0 Because according to your method, the fourth and fifth Numbers can switch places
•  » » 14 months ago, # ^ |   0 因为你第四个数和第五个数可以换位置拉。
 » 14 months ago, # | ← Rev. 2 →   0 why this https://codeforces.com/contest/1167/submission/54206553 is getting runtime error ?I did it like the blog example :(using same code but with cout<
•  » » 14 months ago, # ^ |   0 Seems like you don't separate the numbers in your answer (with spaces).
•  » » » 14 months ago, # ^ |   0 what numbers ? the code can't even run after the first query
•  » » 14 months ago, # ^ | ← Rev. 3 →   0 You forgot the & inside scanf
•  » » » 14 months ago, # ^ |   0 XD XD
 » 14 months ago, # |   0 is D the simple stack implementation ?
•  » » 14 months ago, # ^ |   0 You can also solve it recursively, by using the fact, that all valid sequences S = (A)B, or empty.54212912
•  » » 14 months ago, # ^ | ← Rev. 3 →   0 Yes. Actually, you just have to invert the color before processing a '(' and after processing a ')'.
•  » » » 14 months ago, # ^ | ← Rev. 2 →   0 @MMXIX can you explain your approach in detail,and how does reverting colors gives us required answer
•  » » » » 14 months ago, # ^ |   0 You have to minimize depth, so as you encounter two same brackets in sequence invert your color . This will minimize the depth.Simple greedy approach.
•  » » » 14 months ago, # ^ |   0 Thanks for your comment. I did this in the same way and got accepted but I was in doubt as it 'D' problem.
 » 14 months ago, # |   0 Was O(N logN) supposed to pass on E? I got TLE on test 50 with such an approach. If it was intended to pass, why set the bound as high as 1e6?
•  » » 14 months ago, # ^ |   0 There are O(N) solutions using 2 pointers. However, I think only simple O(NlogN) solutions passed (binary search).
•  » » » 14 months ago, # ^ |   0 I used bs and got WA on test 57. Still can't understand what's wrong.
•  » » » » 14 months ago, # ^ | ← Rev. 2 →   0 Finally found the bug. It is not related to binary search.
 » 14 months ago, # |   0 I don't know what is the hacking format of interactive problems.Somebody help me with an example,please.
 » 14 months ago, # |   0 The problem B could be more interesting if the number of elements would be greater.
•  » » 14 months ago, # ^ |   0 Yeah, it would have been better if the number of permutations were too large for all of them to be checked.
 » 14 months ago, # | ← Rev. 2 →   -13 xx
•  » » 14 months ago, # ^ |   -13 memset gives wrong answer and loop initialization got Accepted.
•  » » 14 months ago, # ^ | ← Rev. 3 →   0 sizeof(vs) is a constant value, you have to multiply it by the size of the array.Correct command would be memset(vs, false, sizeof(bool) * (n+1)) because type of elements in the array is bool. sizeof (vs) will typically be larger (8 bytes) than sizeof(bool).
•  » » 14 months ago, # ^ |   0 vs is a pointer, sizeof a pointer is generally 4 bytes (8 bytes for x64 compilation).
 » 14 months ago, # |   0 Can anyone explain their approach of solving problem D?? I am not able to make up any thoughts about it
•  » » 14 months ago, # ^ | ← Rev. 3 →   +4 let r0 be the nesting of string with color 0, similarly define r1.Initially, r0 = 0 and r1 = 0.now ,each time you encounter an opening bracket, if r0r1, color this bracket 0 (also decrement r0)else color this bracket 1 (also decrement r1).This guarantees that both strings will be balanced bracket sequences because r0+r1=nesting of original string =0 and r0 or r1 can't be negative (because we ensured it in the loop above) so r0=0,r1=0.This also guarantees that max nesting is minimised because only the min is incremented when encountering an opening bracket (always better than incrementing max) and the max is decremented when encountering a closing bracket (always better than decrementing min).
•  » » » 14 months ago, # ^ |   0 Can you explain the proof a little briefly? , it is a nice approach.
 » 14 months ago, # |   0 can someone please explain approach to question D??
 » 14 months ago, # |   +85 The judge doesn't judge.
•  » » 14 months ago, # ^ |   -16 @Radwoosh can you give approach and idea to solve problem D
•  » » 14 months ago, # ^ |   0 MikeMirzayanov this is happening again :/
•  » » 14 months ago, # ^ | ← Rev. 2 →   +1 MikeMirzayanov Judge out of order!!
 » 14 months ago, # |   0 Why is Codeforces so slow after every contest? My past 3 submissions in the virtual contest have not been judged.
 » 14 months ago, # |   0 What is the approach for F?
•  » » 14 months ago, # ^ |   +8 For fixed i, find all j's with (a_i >= a_j), then answer will be the sum of min(i + 1, j + 1) * max(n — i, n — j). Go through i's in increasing order and maintain several fenwick trees.
•  » » » 14 months ago, # ^ |   0 Thanks, a really cool technique I have to say!
 » 14 months ago, # |   +10 I'm very confused. Can someone please explain how to solve E? I have been reading multiple AC solutions but still can't understand the idea behind that!!
•  » » 14 months ago, # ^ |   0 Save the maximum index and the minimum index of each different elements in a. Then think of how to judge a f(l,r) is valid or not in O(1)
 » 14 months ago, # |   0 In problem C, I'm using DFS and getting a TLE in 7th test case. Can anyone help?
•  » » 14 months ago, # ^ | ← Rev. 2 →   +2 Maybe you are not building the graph in an efficient way. Suppose you have 2 5 7 9 Then you don't have to do2->5->7->95->2->7->97->9->5->29->2->5->7 Instead do something like2->55->7->27->9->5 You don't need to make exact graph as you only have to count connected components.
•  » » 14 months ago, # ^ |   0 you can skip visited groups
 » 14 months ago, # |   0 It would be nice, if someone please explain me the problem C using sample Case. I didnt figure out it yet for a while xD. Thanks in advance <3
•  » » 14 months ago, # ^ | ← Rev. 3 →   0 Lets take first case there are 5 groups and 7 people. Each of 5 rows starts with some number that means how many people in Ith group. For example in first group 3 people with number 2, 5, 4 and so on. And problem says if person sends news, their friend can also send info to their friends. After this if person in this group he can share news to this friends and if this friends in other groupes they can share news to other friends in that groupes. At the end we can say that we need to find every component and people in this component can share info with this size of component(including himself). First case if we take person with number 1 he is in two groupes {1, 2} and his friend 2 is in group {2, 5, 4} and if we add this two groups its {1, 2, 5, 4} everyone can share new with themselves that means 4 is the component size. You can solve this problem with dfs or dsu)
•  » » » 14 months ago, # ^ |   0 You said: "First case if we take person with number 1 he is in two groupes {1, 2} and his friend 2 is in group {2, 5, 4} and if we add this two groups its {1, 2, 5, 4} everyone can share new with themselves that means 4 is the component size."But My point is it should be.. if we take person with number 1 he is in two groupes {1, 2} and his friend 2 is in group {2, 5, 4} and{2, 6, 7} and if we add this three groups its {1, 2, 5, 4, 6, 7} everyone can share new with themselves that means 6 is the component size." Can you please clear my confusion. Thanks xD <3.
•  » » » » 14 months ago, # ^ | ← Rev. 2 →   +1 2 6 7 doesnt mean fifth group contains {2, 6, 7} first number means how many people in this group, in this example 2 people in fifth group with numbers {6,7}
•  » » » » » 14 months ago, # ^ |   0 Oh hoooo. Thats clearly show how bad I am in problem statement reading. But Thanks a lot xD. Take love <3
 » 14 months ago, # |   0 could you help me check where is wrong? ID:54220798
 » 14 months ago, # | ← Rev. 2 →   0 In E, is it okay to find the max l value and min r value such that l<=r , and f(l,r) is valid. Then we know that f(l-k1,r+k2) is also valid for all possible values of k1 and k2.
•  » » 14 months ago, # ^ |   0 That is true but not enough. For example, leaving one element only inside leaves array sorted, if l != r, then we can leave l + 1
•  » » » 14 months ago, # ^ |   0 couldnt understand
•  » » » » 14 months ago, # ^ |   0 I mean, what if l = n and r = 1. Which max l value and min r value do you choose? If you iterate all, then you count some segments several times.
•  » » » » » 14 months ago, # ^ |   +1 but l<=r
•  » » » » » » 14 months ago, # ^ |   0 What about this case. 1 4 2 5. f(4, 4) = 1 2 5. it is valid and we cannot make l bigger or r smaller, because then l > r. So you are saying that all f (4 — k1, 4 + k2) are true for positive k1 and k2, as I can tell. Well that is right. But we also have f(1,2), for example -> 4 5. And it is not of this form, 4 + k2 = 2 so k2 is negative.
•  » » » » » » » 14 months ago, # ^ |   0 Oh, I understood. So you mean that 4-k1 and 4+k2 is correct but it leaves out other cases... because l is unable to become greater than 4 and r unable to become smaller than 4.... Is this what you meant?
•  » » » » » » » » 14 months ago, # ^ |   0 Yes
 » 14 months ago, # |   0 Why using Dfs to get number of nodes in each connected components gives wrong https://codeforces.com/contest/1167/submission/54223559
•  » » 14 months ago, # ^ |   0 You are assigning the value of c to val[i] while running dfs, c being the number of connected components, this doesnot ensure that the parent of all these components is 'i' and therefore the answer is coming out to be less than than the actual number of components. Just a little bit of change and there you go..!!! 54225792PS-- This might give you TLE in system tests as you have not used weighted dsu.
 » 14 months ago, # |   0 Hope that I can reach 1600, it is only 12 ratings away but it seems that I am not performing well this time... Btw I really appreciate problem B as an interactive task, as we don't get to meet them often and this is a great opportunity to train up skills related to interactive tasks.
•  » » 14 months ago, # ^ |   +1 You're right. This is my first interaction problem.Wish you can be blue name
•  » » » 14 months ago, # ^ |   0 Thanks!
•  » » 14 months ago, # ^ |   +6 I think you will :)
•  » » 14 months ago, # ^ |   0 congratulations！
•  » » » 14 months ago, # ^ |   0 Thanks!
 » 14 months ago, # |   0 I'm new here. Are these contests are Python friendly? Most people solved C with Union Find in C++ and passed the tests, but the same algorithm in Python gets TLE
•  » » 14 months ago, # ^ |   0 In div2 and div3 (and most div1) problems can be solved with Python. With medium plus problems, if there is too much list reading or query you will need Pypy3. There are lots of difficult problems looks impossible with Python but we're far away from them (I'm trying to solve some of them on Codechef and even with 5x time limit it's still a big challenge, my current problem). And here Python solution for C: link
•  » » » 14 months ago, # ^ |   0 Thanks, the key was to change input() to sys.stdin.readline() https://codeforces.com/contest/1167/submission/54233244 Anyway it's strange that the time limit for python and c++ is the same number.And why do you need work with stdin? In real life in 99% you need to write class of function, so why not just give a prototype of the function or class that you need to implement? def solution(n: int, m: int, lines: List[int]) -> List[int]: """ :param n: number of users :param m: number of groups :param lines: number of users in group + users in group :return: the number of users that will know the news """ Sorry for my questions, I'm new here.
•  » » » » 14 months ago, # ^ |   0 Actually you're right about writing a class of function, but here I most time coding what I need for current problem. I'll use libraries if I go up in rank :) For stdin, I only use it when there is lots of reading like in that problem.Don't worry about time limit, it's something classic CP thing but Codeforces gives extra time for problems. You'll start to need C/C++ solutions if you become a Div1.
•  » » 14 months ago, # ^ |   0 See solution of @algmyr he passed the problem probably with union find
 » 14 months ago, # |   0 I wonder when I can see the ratings changing...
 » 14 months ago, # |   0 Easy busy contest
 » 14 months ago, # |   0 Why Radewoosh's submit 54183325 didnt get TLE? In his solution (sorry for my poor English) he didnt use rank's heuristic and got AC. I tried to submit solution without rank's heuristic and got TLE 54233682 . Could someone help handle it, please?
•  » » 14 months ago, # ^ |   0 And im about problem C.
•  » » 14 months ago, # ^ |   0 Because he used a technique called 'Path Compression'.
•  » » 14 months ago, # ^ | ← Rev. 2 →   +7 In his code int fin(int v) { if (v!=oj[v]) oj[v]=fin(oj[v]); return oj[v]; } not int fin(int v) { if (v!=oj[v]) return fin(oj[v]); return oj[v]; } So after a fin(v) operation, the nodes on the path from v to the root will all directly connect to the root.Therefore, when you perform fin(i) (i is a node on the path from v to root) will just return oj[i]
 » 14 months ago, # |   +12 Wait for tutorial
•  » » 14 months ago, # ^ |   -7 dont tell me what to do
 » 14 months ago, # |   0 I have passed problem G, but I have no idea whether my solution has a right complexity.My solution is 54235792. It uses a method similar to two-pointer to find the nearest pair that is the same far from point x.Could someone please tell why it's correct or construct a data that will lead to a TLE?
 » 14 months ago, # |   +15 I got compilation error on problem D during system test after it passed during the contest? How is that? :D54189857
 » 14 months ago, # | ← Rev. 2 →   +15 Here is my $O(N)$ solution for problem E: 54241182The general idea is to maintain, first of all, a global rightmost $L$ and a global leftmost $R$ such that ranges $[1,L]$ and $[R,X]$ are valid, then for each $r$ the rightmost $l$ such that the union $[1,l] \cup [r,X]$ is valid too.
 » 14 months ago, # | ← Rev. 2 →   +2 Used DSU for problem C, got WA test 3 and I cant find the mistake, can anyone help? 54184178 Edit: Found the error, I was not checking if nodes are already connected before connecting them.
•  » » 14 months ago, # ^ | ← Rev. 2 →   0 same for me.then I used dfs and it got ac.I don't know what is the mistake.
•  » » 14 months ago, # ^ |   +1 I also got WA test 3. You should check in your connect function that you don't connect the same element.
 » 14 months ago, # |   0 Hello, I tried solving problem C and I was getting TLE error on test 3. Somebody please help in optimizing my code. I didn't get the editorial properly. Here is my code: https://codeforces.com/contest/1167/submission/54269390
•  » » 14 months ago, # ^ |   0 The answer is the same for vertices in same connectivity component. You dont need to clean the array.
 » 14 months ago, # |   +4 How to solve problem G?
 » 14 months ago, # |   0 can any one explain E problem please ?
 » 14 months ago, # |   0 problem D, solution1 got accepted whereas solution2 gave TLE. The only difference between the two is in line number 21. In solution1 we append 0 in string by res+='0'. In solution2 we append by res=res+'0'. I thought these two operated the same way. Can someone give insight to the reason?
•  » » 10 months ago, # ^ |   0 the first solution, you modify the res string, fill the data in string if possible, or create new string if not possible, just like vector push_backthe second solution, you create new stringthe first solution is possible because c++ string overload that operator http://www.cplusplus.com/reference/string/string/operator+=/
 » 13 months ago, # |   0 Someone please help me with problem C. I am getting MLE. Any help would be appreciated. https://codeforces.com/contest/1167/submission/54526141
 » 2 months ago, # |   0 78428168 78426655 Why did this same code got accepted with C++17 while it got TLE on C++17(64)? All i did was change the array size.. That should've given a RE instead of TLECan anybody explain?