By BledDest, history, 7 years ago,

Hello Codeforces!

On September 21, 18:05 MSK Educational Codeforces Round 29 will start.

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.

The round will be unrated for all users and will be held on extented ACM ICPC rules. After the end of the contest you will have one day 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 prepared by Mikhail awoo Piklyaev, Mikhail MikeMirzayanov Mirzayanov, Vladimir vovuh Petrov and me.

Good luck to all participants!

• +172

| Write comment?
 » 7 years ago, # |   +5 For a joke, How to solve the terrible problem A?
•  » » 7 years ago, # ^ |   0 As what I said, HOW TO SOLVE THE TERRIBLE PROBLEM B??My idea is: priority_queue make all the value of (abs(w[a]-w[b]) (1<=a,b<=2*n,a!=b)) into the queue, and choose the national w[a] — w[b], then the (n-1) pair of (w[a] — w[b])'s sum is my answerIs'it something wrong with my idea? I need all of your help,thanks!
•  » » » 7 years ago, # ^ |   +2 You have n*(n-1)/2 ways to pick single guys. So for every combination calculate new value and take the minimum.
•  » » » » 7 years ago, # ^ |   0 Get it now, thanks！
•  » » » 7 years ago, # ^ |   0 There is open-hacking for 24 hours, please don't discuss problems before this phase ends.
•  » » » » 7 years ago, # ^ | ← Rev. 2 →   +49 i think we should discuss the problems because we can get more ideas for hacks. It is not rated anyways,so i don't see any problems
•  » » » 7 years ago, # ^ |   0 The idea is wrong.because the value “a” or “b” will be chosen more than once. However,a man only belongs to one ship. In fact,we should try to pick two people out and do not consider them. Now we have 2n-2 people.we sort the array by weight. After sorting .the answer is the sum of whose index is even plus the sum of whose index is odd.
•  » » » » 7 years ago, # ^ | ← Rev. 2 →   0 But i marked both whose diff is minimum...but still showing error...?? as shown: (a[i]-a[j],{i,j})if(!(vis[i] || vis[j]) ans+=a[i]-a[j]
•  » » » » » 7 years ago, # ^ |   +1 Maybe you should try to think about this example. N = 3 1 5 6 20 1000 2000 And ans should be 18Your output is 20?
•  » » » » » » 7 years ago, # ^ |   0 TvT...I should first choose two single.And choose double two by two, Igot it now, thank you!
 » 7 years ago, # |   +167 uwi be like :
•  » » 7 years ago, # ^ |   +24 If uwi is in hacking mode, we will not need system testing after the round.
 » 7 years ago, # |   +11 Another ROUND!!!!where u can relax about Rating.The more u dont want to care about ratings the more u start to care....Why rating is so cruel!!!!!!!!!!!
 » 7 years ago, # |   -20 Is it rated?
•  » » 7 years ago, # ^ |   +3 No, the Educational Codeforces Round is based on ACM rules, so it is unrated.
•  » » » 7 years ago, # ^ |   +6 Pardon me, but how do those two go together?
•  » » » » 7 years ago, # ^ |   +2 All the rated rounds are based on Codeforces rules, so if the round isn't based on Codeforces rules, it's often unrated.(Maybe I was wrong,it is unrated just because it's an Educational round).
 » 7 years ago, # | ← Rev. 2 →   +69 This question is for uwi and halyavin.Just out of curiosity, hacking solutions is a way to learn something new or you guys just pass your free time by hacking hundreds of solutions in Educational rounds ?
•  » » 7 years ago, # ^ | ← Rev. 2 →   +53 not much time needed, it's probably a script that automatically download source code , compile and run it , they only need good hacking tests , or if you feel lazy just randomly generate some tests and compare the output to a non hackable solution ,you can check TLE/RE errors too.
•  » » » 7 years ago, # ^ |   +3 That's a legend thinking approach !
•  » » » 7 years ago, # ^ |   +3 Wait, I never realised you can download solutions in text form during educational rounds! Well, well, well...
•  » » 7 years ago, # ^ |   +60 I do learn new things while trying to hack solutions. This type of thinking helped me to construct the worst test case for my own contest problem recently.
•  » » » 7 years ago, # ^ |   0 How did you download all this code at a same time??
•  » » » » 7 years ago, # ^ |   0 Maybe he used a crawler
 » 7 years ago, # |   -8 I need to check the rules of ACM-ICPC. Can anybody send the link?
•  » » 7 years ago, # ^ | ← Rev. 3 →   +19 It turned out, that searching "ACM ICPC rules" gives some results.
 » 7 years ago, # |   -10 i hope someday , somebody write a contest about DOTA 2 it would be so nice :D
•  » » 7 years ago, # ^ | ← Rev. 2 →   0 Dead Game, Dead GameI Love Dead Game
 » 7 years ago, # |   +60 Getting Hired.. uwi mode
 » 7 years ago, # |   -26 When is this and is it rated?
•  » » 7 years ago, # ^ |   +1 Educational Round is not rated. And you can also check from Codeforces Calendar
 » 7 years ago, # |   +14 Hi , This will be my first Codeforces contest !
•  » » 7 years ago, # ^ |   +41 please don't bomb the contest, we beg you, it's only educational to serve the country...Please someone tell uwi to not hack this guys
•  » » 7 years ago, # ^ |   +3 You are DED
 » 7 years ago, # |   +22 The days are gone forever when our enemies could blackmail us with nuclear bombs.
•  » » 7 years ago, # ^ |   +3 Scary.
 » 7 years ago, # |   +10 Time to BOMB test case #3 of Problem B
•  » » 7 years ago, # ^ |   +8 You are behaving very badly, Rocket Man.
•  » » » 7 years ago, # ^ |   +4 We will have no choice but to totally destroy the problemset!
•  » » 7 years ago, # ^ |   0 you can pass it and get ac if you add one line
 » 7 years ago, # | ← Rev. 3 →   +3 Test 14 in E?
•  » » 7 years ago, # ^ |   0
 » 7 years ago, # |   +3 What is test 14 in E?
•  » » 7 years ago, # ^ |   +22 If you are compressing the values, you should add (r[e] + 1) to the values to compress, at least I did this and passed
•  » » » 7 years ago, # ^ |   0 Can we solve that questions using Compression and BIT ???
•  » » » » 7 years ago, # ^ |   0 I probably wrong , but i don't think so, we can't get the minimum of a range with BIT and do range updates at the same time.
•  » » » » » 7 years ago, # ^ |   +3 there is a way to do that,but it is tricky to code and it is not worth using instead of seg tree :)
•  » » » » » » 7 years ago, # ^ |   0 I actually implemented that method but somehow I'm getting a WA. I have used a BIT for the cumulative sum. Getting WA on 16th test case. Here is a link to the code. Can you have a look of what I might be doing wrong. https://code.hackerearth.com/0ec204e?key=4b7fb07878fac98d3c5bcc41899f3436
•  » » » » 7 years ago, # ^ |   +3 My solution is: suppose the elements l[e], r[e] <= 105 If you add 1 to every element in the range [l[e], r[e]] for every e , you can check if a range is good checking if the minimum element in the range is 1. Because if the minimum is 1 after deleting that range we gonna have at least a 0, what means that the number of moments increased.
•  » » » 7 years ago, # ^ |   0 Any reason why compression with l[i],r[i],l[i]-1,r[i]+1 works?
•  » » » » 7 years ago, # ^ |   0 Basically, you have to see that some number may be 'lost', what I mean is that when we are compressing we are not considering the elements l[e] < X < r[e], for every e, so we can create a case were there is more that an range loses one of it's elements and after this our algorithm gives the wrong answer, but actually we don't have to take exactly all the X, if this situation gonna happen is because of there is two ranges with some intersection, so the values that matters are the borders of the ranges, it's not a good answer, but if it's not clear I can try to explain in a better way
•  » » 7 years ago, # ^ | ← Rev. 4 →   +14 this is a test like it31 35 72 6correct answer:-1
•  » » » 7 years ago, # ^ |   +3 Thanks
 » 7 years ago, # |   0 How to solve E? (and why i'm getting RTE with a simple segtree?)
•  » » 7 years ago, # ^ |   +6 the seg tree dimenison is too little,it should be 4*2*MAXN
•  » » » 7 years ago, # ^ |   +3 Oh, i see, thank you :)
•  » » » 7 years ago, # ^ |   0 I tried to solve it using segment tree with range sum updates and range min query first i do coordinate compression and then i will update from 1 to n all queries with +1 to their corresponding range and then i will start from 1 to n and at an i th position i will remove that update by adding -1 to that range and check if in that range iam getting any 0 if NO THEN that is a valid ans as it is not affecting others's //(using range min query ) but the problem is i was unable to implement it in time .and also can't we implement a segment tree with range sum updates and range min queries??
•  » » » » 7 years ago, # ^ |   0 You don't need range min queries. What you need to know — is there any element on range equal to 1. Just access each element of your tree and build an array of prefix sums with amount of 1's on prefix, like this: prefixSum[i] = prefixSum[i-1] + (tree.get(i)==1). Then some segment [l; r] is an answer if prefixSum[r] - prefixSum[l-1] == 0
•  » » » » » 7 years ago, # ^ | ← Rev. 2 →   0 tnx , cool idea to solve that question(we don't even need a segment tree we can use partial sum trick ) . btw i have a doubt in general not regarding this question but can we code a segment tree with lazy propagation such that we can do range sum updates (i.e we can add a value v from l to r ) and we can do range min queries (i.e we can find minimum in that range from l to r ) in logN time .
 » 7 years ago, # |   0 I tried to solve D using treap, I think it is an overkill but it should work! I got RE on test 10 and 11 ... it's weird
•  » » 7 years ago, # ^ |   +14 I'm not sure, but it might be because you put the priorities as rand () (up to 32000 on CF compiler). If you extended the set of possible values, the possibility of two priorities being equal on adjacent positions (which most treap implementations consider 0) would dramatically decrease. I use treaps with rotations and in that implementation in function erase, if you have two neighboring nodes having the same priority and do not pay special attention to the case, you might end up with a loop. Let alone that such small values cut off the idea of normal distribution, so even if you hadn't gotten RE, you would've gotten TLE. Try to switch that line of the code with something like p = (rand () << 15) + rand ().
•  » » » 7 years ago, # ^ |   +10 You are right! It worked. I completely forgot about that detail.I must say, I have been very lucky because I have always used just "rand()" in these kind of problems.Thanks!!
•  » » 7 years ago, # ^ |   +3 Actually, I did the same overkill :)
•  » » 7 years ago, # ^ |   0 How can you reverse the segment using treap?
•  » » » 7 years ago, # ^ |   +13 Each node should contain a bit which indicates whether you need to flip it or not. To flip a segment, split the treap into three parts (propagating the flips as needed), change the flip bit on the middle part, and then merge the parts.
•  » » » 7 years ago, # ^ |   +58 Another approach is to build two treaps. One for the initial array and another for the reversed array. If you have to reverse a segment you swap the corresponding segments in these treaps.
 » 7 years ago, # | ← Rev. 2 →   0 very interesting problemset.
 » 7 years ago, # |   +20 I laughed so hard when I saw SPFA_THE_BEST_ALGORITHM's nickname, knowing it is part of the solution to problem F :D
 » 7 years ago, # |   0 Simple solution to problem E, no data structures needed (other than array) 30592259PS: I hope nobody hacks it !
•  » » 7 years ago, # ^ |   +16 just found a little hack, if you fix it I would try again, although the solution approach seems kinda correct to me :)
•  » » » 7 years ago, # ^ | ← Rev. 3 →   +5 Sure ill try to fix it later (order needs to be x increasing then y decreasing), i also believe it to be a correct approach, but i seem to be unable to code without bugs lately.Edit: fixed version, with the change previously described 30727493
 » 7 years ago, # |   0 Is there solution for D easier than treap solution?
•  » » 7 years ago, # ^ |   +17 Do the operation backwards. For every b, do the operations in reverse to find where the number would have started. Then print that number. Complexity is O(m * q).
 » 7 years ago, # |   -26 Hi guys, I did join this website yesterday. and I am really happy for this. Few minutes ago I did submit my attempt to solve the problem A but I see runtime error on test1.I am quasi sure that my solution is working well. I did use java. should I stop using things like demanding the user to enter an input "java.util.Scanner" ? please help me!The solution is bellow : package javaapplication7; import java.util.Scanner; public class JavaApplication7 { public static void main(String[] args) { //Reading user's number and adding leading zeros Scanner s = new Scanner(System.in); System.out.println("Enter the number please"); Long in = s.nextLong(); String in_to_str = in+""; int in_last_index = in_to_str.length()-1; String sub_str_to_add = ""; while(in_to_str.charAt(in_last_index)=='0'){ sub_str_to_add=sub_str_to_add+"0"; in_last_index--; } in_to_str = sub_str_to_add + in_to_str; //testing whether it's a palindromic or NOT int in_len = in_to_str.length(); int ind_diff=-1; for (int start=0,end=in_len-1;startin_len/2;end--,start++){ if(in_to_str.charAt(start)!=in_to_str.charAt(end)) { ind_diff = start; break; } } /* the second part of the if condition [in_len==2&&in_to_str.charAt(0)!=in_to_str.charAt(1)] is to treat the case of a number composed of two digits which is not included in the previous test */ if(ind_diff
•  » » 7 years ago, # ^ | ← Rev. 2 →   +4 Remove "System.out.println("Enter the number please");" and see if it goes awayAlso you are supposed to output only "YES" or "NO".
 » 7 years ago, # | ← Rev. 2 →   0 how should i approach problem E? Thank you.
•  » » 7 years ago, # ^ |   +8 Create a map m which will compress the indices. The interval [l, r] will be transformed to m[l], m[r + 1] - 1. Now either Use a lazy segment tree to add to a range and query the minimum along a range. A TV is redundant iff the minimum number of TV's at any integer point in time from l to r inclusive is greater than 1. This works well if you already have a template prepared. :) Create a cumulative sum table, which will allow you to determine all points in time where exactly 1 TV is working. Now for each TV you can query if any of these points are inside [l, r] with a set. If none of them are inside, then this TV is redundant.
•  » » » 7 years ago, # ^ |   0 There is a simplier solution without indices compression and segment tree:The main idea, that TV (l, r segment) is redundant if it fully overlapped by one or two consecutive segments (proof is pretty easy). So algorithm looks like: Sort all segments in ascending order of r (for equal r in desc order of l) Iterates over segments, lets look to the set of the segments that already viewed and pick segment with maxL, and segment with maxR (this segments must be different), so segment with max L is redundant only if it overlapped by current segment or by current segment & segment with maxR. 30588470
•  » » » 7 years ago, # ^ |   0 Can you please explain why indices left — 1 and right + 1 are compressed along with left and right?
•  » » » 7 years ago, # ^ |   0 I followed the exact same approach but somehow I'm getting a WA. I have used a BIT for the cumulative sum. Getting WA on 16th test case. Here is a link to the code. https://code.hackerearth.com/0ec204e?key=4b7fb07878fac98d3c5bcc41899f3436
 » 7 years ago, # |   0 Hey! I am new to codeforces. Can anyone guide me ?
•  » » 7 years ago, # ^ |   +5 Start solving problemset starting from Div II A, B. Learn some algorithms and DS and then jump to Div I. Participating in contests is a must. Read other people's solutions and be most important be optimistic.
 » 7 years ago, # |   +36 Because hacking others' solutions is too mainstream.
 » 7 years ago, # |   0 How to solve the problem D?I have no idea on data structure,could someone give me a little help?
•  » » 7 years ago, # ^ | ← Rev. 2 →   +23 Consider the number of queries is smaller in 100, we can calculate for every single query for the operations but not the whole sequence. As we are given the ending position of the number, we can calculate it's beginning position. For the operations,we can consider it in reverse order.Let's call the position of the query is now x,and consider the operation done before it become x.First. the operation reversed [l,r],then if the x is in [l,r] it should be l+r-x before this operation.Second. the operation shift [l,r] ,then if x is in [l,r] it should be x-1 before this operation. but if it's l exactly it should have been r.So you can solve the problem in O(nq).Sorry for my poor English, if it's still not clear, you can ask again.
•  » » » 7 years ago, # ^ |   0 @pb0207, can you give me explanation sample test case for problem D?Problem statement aren't clear to me.Specially first operation isn't clear to me.
•  » » » » 7 years ago, # ^ |   0 The first operation is a cylic shift which is that all the numbers in the interval [l,r] goes right except the number on the position r which goes to l.That means for the array [1,3,2,4,5,6,7,9,8] if we do the first operation to the interval [2,5] , it would be [1,5,3,2,4,6,7,9,8]The second operation means to reverse the interval.Which means if you do this operation to the interval,then you can find the previous interval by reading from right to left. And for more formal explanation the number on position l would be equal to number on r,and l+1 equal to r-1 ,etc.And for the array [1,3,2,4,5,6,7,9,8],if we do the second operation to the interval [3,7] , it would be [1,3,9,7,6,5,4,2,8]
•  » » » » » 7 years ago, # ^ |   0 pb0207 Thanks for your time ,consideration and forthcoming response. Sample testcase; - 6 3 5 - 1 2 3 4 5 6 - 2 1 3 - 2 3 6 - 1 1 6 - 2 2 1 5 3 for 2 1 3 array would be 3 2 1 4 5 6 for 2 3 6 array would be 3 2 6 5 4 1 for 1 1 6 array would be 1 3 2 6 5 4 for 2 2 1 5 3 answer would be 3 3 1 5 2 Isn't it?
•  » » » » » » 7 years ago, # ^ |   0 Yes, that's right.
•  » » » 7 years ago, # ^ |   +3 This helps a lot thanks!I was confused with this problem but now i get it! :')
•  » » 7 years ago, # ^ | ← Rev. 2 →   +4 As for data structure, you can learn Treap or Splay which can reverse the array.And you can calcultate the final array in O(logn) for each operation.
•  » » » 7 years ago, # ^ | ← Rev. 2 →   0 Hi pb0207 Do you know a good reference about treap and its reverse operation?? I've read a couple of pages about treap but they don't mention that!
•  » » » » 7 years ago, # ^ |   +4 As I mentioned here, you can use lazy propagation to flip a segment of a treap. See my submission for its implementation.
 » 7 years ago, # |   0 For problem B, can any body explain why this approach is wrong:iterate over all pair and find the pair with minimal absolute difference between weights, then delete them and repeat the process.This gives a WA, any proof why it's wrong.
•  » » 4 years ago, # ^ |   0 I also don't understand how to prove these approaches wrong.I know this is an old post but maybe anyone can help as I usually get stuck on these types of wrong approaches.
 » 7 years ago, # |   +14 When will be editorial published?
 » 7 years ago, # | ← Rev. 3 →   0 For problem E,why segment tree is not able to solve this problem?(I have change the array a for discretization) but I got WA on test 14.The main idea I do is to add 1 in segment[l,r] and query the minimum value in this segment after all the add operations are done.Then if there is a segment whose minimum value can be greater or equal to 2 ,then this TV set is not needed.It's that my fault in writing segment tree?But I'm so sure I could at least write a segment tree correctly...This is code...Please tell me what's wrong or just point out the solution itself is not correct...Thanks in advance...
•  » » 7 years ago, # ^ | ← Rev. 2 →   0 i too taught segment tree. but seeing values of array, i solved it in another way. i used binary search. 30619432
•  » » » 7 years ago, # ^ |   0 Thank you for reply...But is there any monotonicity for binary search in this problem?I just think it's asking about whether there has a segment which have been covered by other segments completely...
•  » » » » 7 years ago, # ^ | ← Rev. 3 →   +1 Yes and you can search that segment using Binary search by doing some preoprocessing. let me explain it. example: 31 22 33 4lets sort this segments by l and if same then by r.array = (1, 2) (2, 3), (3, 4)now we will create new vector where we will store working time of tv's based on previous tv.for example : (1, 3) (2, 5) as you can see the second segment (l2) is lying inside 1st segment. so we can write this as (1, 3), (4, 5). so here we converted the 2nd segment l to new time which is equal to r1 + 1.if r1 + 1 > r2, this means that second tv is totally not needed so we can output this as answer. for example: (1, 3) (2, 3). after building this new vector for out previous example it will look like this:array = (1, 2) (2, 3) (3, 4)newtime = (1, 2) (3, 3) (4, 4)now for each segments in newtime find how many segments are there in array. if there are more than one then this segment is not needed. for this use binary search, find the leftmost segment and then find the rightmost segment. count = (rgt — lft) + 1.
•  » » » » » 7 years ago, # ^ |   0 OK,I got it! Nice solution! Thank you.
 » 7 years ago, # |   0 can anyone please tell me how to approach the problem B i tried all possible solutions from my side
•  » » 7 years ago, # ^ | ← Rev. 2 →   0 Sort and then apply DP http://codeforces.com/contest/863/submission/30594941
 » 7 years ago, # |   +5 When will the editorial be posted? Hacking phase is over already.
 » 7 years ago, # |   0 I need editorial of problem F.Can anyone please explain how to model flow network for this problem.
 » 7 years ago, # |   0 How to solve G?
 » 7 years ago, # |   0 Sorry for the late editorial, it is published now.
•  » » 7 years ago, # ^ |   0 I'm sorry but where exactly can I find it? I don't see any link to it
•  » » » 7 years ago, # ^ |   +3 Here is the link to the editorial
 » 7 years ago, # | ← Rev. 8 →   0 anyone can help check whats wrong with my solution for problem E, got RTE for 16th test case. http://codeforces.com/contest/863/submission/30694287
•  » » 7 years ago, # ^ | ← Rev. 6 →   +5 The problem is in cmp function. Your comparator must always be like: if cmp(a, b) then !cmp(b, a). UPD: And one more mistake is in if-statement in main function.
 » 7 years ago, # |   0 is there answer?