Um_nik's blog

By Um_nik, history, 5 years ago,
• +65

| Write comment?
 » 5 years ago, # |   +1 Editorial will be published.
 » 5 years ago, # |   0 Now we have to choose no more than K consecutive values in such a way that they cover as much elements as possibleShouldn't it be Now we have to choose no more than K consecutive values in such a way that they cover as less elements as possible
•  » » 5 years ago, # ^ |   +3 No
•  » » 5 years ago, # ^ |   +12 The more elements it cover, the less it has to be changed.
 » 5 years ago, # | ← Rev. 4 →   +10 Could any one please explain (Div1 F) more clearly because I find it actually hard for me to get the proves for those observations.also (Div1 D) the same thing.any help would be appreciated.thanks,
 » 5 years ago, # |   0 Isn't it better to use kuhn's algorithm for problem Div 1 E if we want to find max matching?
•  » » 5 years ago, # ^ |   0 Ups I am probably wrong
•  » » 5 years ago, # ^ |   -14 It's not a bipartite graph and kuhn munkres only works on bipartite graphs. Plus kuhn munkres will probabably TLE. Correct me if I am wrong
•  » » » 5 years ago, # ^ |   +3 "...we will build a bipartite graph "
•  » » » » 5 years ago, # ^ |   -8 We can not build a bipartite graph if the graph contains odd cycles...
•  » » » » » 5 years ago, # ^ |   +9 Left part — columns Right part — rows
•  » » 5 years ago, # ^ |   +11 The graph you are building is bipartite and what you want is indeed max matching, but when you compress vertices you turn $m$ edges going into $m$ equivalent vertices into a single edge with capacity $m$. So the problem you actually solve in the compressed representation really is maxflow and not just max matching.
•  » » » 5 years ago, # ^ |   +3 Thanks
 » 5 years ago, # |   -9 For div1 A doesn't the N change every time you compress?
•  » » 5 years ago, # ^ |   +3 No, the n is the length of the array, not the amount of different values in the array.
 » 5 years ago, # | ← Rev. 2 →   +36 My alternate solution for C:Consider the DFS Trees of the connected components in the graph, we can pair the nodes in such a way that only nodes left unpaired are leaves by pairing each unpaired node with a random child, so in worst case we have got a matching of (3*n-x)/2 edges where x is the number of leaves. if (3*n-x)/2 >= n, output this otherwise x must >= n , so output any n leaves. Note that the leaves form an independent set because in DFS tree all non-tree edges go to an ancestor.
 » 5 years ago, # | ← Rev. 5 →   +64 Are the top 6 solutions really of only of 3 — 4 lines and rest 6-8 lines or you did a huffman coding on them ? very short. one can write editorials like : basically we can do it in O(n^5) by using our mind.also it can be written as : AA! this is easy , look other solutions for it.morover : It can be solved in O(N)a step forward : you can use any langauge to solve this problem. solve it on your ownbaby giant: see how radewoosh and tourist solvedfinally : editorial is missingReally no intention of writing editorial. wrote just for formality
•  » » 5 years ago, # ^ | ← Rev. 2 →   +19 Let's do subset DP — our state is what primes are still alive. This solution has complexity O(n^2 2^k). __ what about transitions. You can write it like : No need to look at editorial, solve using dp.
•  » » » 5 years ago, # ^ |   +13 He explicitly gives you the dp states and the transition is just naive. He may assume that people who read this editorial have a basic sense of how dp works (bcs it's a Div1 pF), and the transition is just an (and trivial) exercise. If you really have no idea what he says, then do some exponential states dp problems first, or just simply ask for details here instead of complaining.
•  » » 5 years ago, # ^ |   +15 This is absolutely trueI wanted to say exactly that
•  » » 5 years ago, # ^ |   +5 Editorial is perfectly fine. He gave the crucial observation required for the recurrence(_Of course, we can cover all rectangle with itself for cost W. To get something smaller than W we have to leave at least one column uncovered — otherwise we pay at least sum of w over all rectangles which is at least W._). If you want everything comprehensively for the simple things, you just destroys that problem for yourself instead of gaining something from it.
 » 5 years ago, # |   0 in div1C/div2E can you prove the line : "Either matching or independent set has size at least n"?
•  » » 5 years ago, # ^ |   +16 You keep choosing edges for a potential matching, as long as there is an edge between two unused vertices. If the number of edges you find in this manner is at least n, you found a matching of at least n edges. Otherwise, you have used fewer than 2n vertices and there are at least n vertices remaining, which have no edge between any two of them. Therefore the unused vertices form an independent set of size at least n.
•  » » » 5 years ago, # ^ |   0 Got it! Thanks!
•  » » » 5 years ago, # ^ |   0 Thank you so much!
 » 5 years ago, # | ← Rev. 2 →   0 I'm getting time limit exceeded on div1C, even though my solution is O(n+m) like the tutorial says. Is 1 second too short given the input constraints or am I missing an easy way to improve my solution?
•  » » 5 years ago, # ^ |   0 Update: Accepted when I added ios::sync_with_stdio(false);
•  » » » 5 years ago, # ^ |   0 Could you please explain what does this do
•  » » » » 5 years ago, # ^ |   0 Solution got TL on tests with large input, so the problem is how to read a lot of data fast. You can read how the thing above optimizes the time here: https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio (Using of printf and scanf usually fixes all the issues connected with input/output, so by using them you can protect yourself from stupid TLs)
•  » » 5 years ago, # ^ |   0 The time constraints do seem rather tight in this set given the input sizes and expected time complexity...
 » 5 years ago, # |   0 Can someone plz explain for Div2/D How can we do it in O(n+q)?
•  » » 5 years ago, # ^ |   +5 You can use count sort and two pointers, but that wasn't needed. My solution is $O(q + n \cdot log(q))$.
•  » » 5 years ago, # ^ |   0 Loop from the last query to the first. If we get query type 2, save the maximum type 2 from the last query to the moment. Otherwise, if we get query type 1, update the value at index x with max(max_type_2_now, value from query) and flag it so we will never update it again.After the query done, loop through the entire array. If the cell is not flagged, update the cell with max(max_type_2, A[i]).
 » 5 years ago, # |   +11 I used another approach in div1-C / div2-E. I'm not sure if my idea is correct. Can someone give me a counterexample (or hack my solution) ? Submission : 58029374Idea : sort all the nodes with respect to their degree. First let's try to form an independent set. So we iterate through the nodes and if it isn't marked, then we add it to our list and marked all its neighbours. If the list has size >= n , we're done . If size < n , we do almost the same in order to find a matching. In the same order we iterate through the nodes and if it isn't visited we try to find a neighbour that is not visited. If we find such a pair, we add it to our list of matching and we visit both nodes. But I'm not sure if this matching has size >= n in all the cases.
•  » » 5 years ago, # ^ |   +234 Done
•  » » » 5 years ago, # ^ |   +5 Thank you very much
•  » » » 5 years ago, # ^ |   +39 tourist orz
•  » » 5 years ago, # ^ | ← Rev. 2 →   +3 A smaller case click here (idea from tourist)
 » 5 years ago, # | ← Rev. 2 →   0 @Um_nik Please provide code implementations of problems DIV 1:C,D,E.it would be 25 min work for you, but it would be of great help in understanding the code details of the solution.
 » 5 years ago, # | ← Rev. 3 →   0 1198B — Welfare StateCould someone explain efficient way of finding maximum of all x for queries of type 2 after latest query of type 1? I can't invent fast solution unless using sparse table. Thank you in advance.
•  » » 5 years ago, # ^ |   +4 It is quite simpler than that, just maintain a suffix array lets call it maxSuff of size q and for each query of type 2 assign maxSuff[i] to x, where i is the index of that queryand then run a loop through i from q-1 to 0 and assign maxSuff[i] to max(maxSuff[i], maxSuff[i + 1])solution for better understanding 58077496
 » 5 years ago, # |   +5 May someone please explain how the formula was derived in Div2 B? Thanks.
•  » » 5 years ago, # ^ |   +1 Note that the length of the flower will remain constant. When the flower was straight the length = depth of river(d) + H. When the flower is tilted then you can apply Pythagoras theorem where the hypotenuse= length of the flower.
•  » » 5 years ago, # ^ |   +1 First of all, you have to notice that green lines are equal. Pythagorean theorem for triangle: Ans^2 + L^2 = (Ans + H)^2Solve the equation above.
 » 5 years ago, # | ← Rev. 4 →   0 The time limit + test size for 1198A — MP3 is really tight. My Kotlin solutions pretty much match the tutorial solution but this one didn't pass, and this one only barely passes (2 ms to spare!) after I switched to a TreeMap for the counts and an IntArray for the prefix sums. I wonder if anyone could pass this with something like Python.Edit: And when I tried to bypass storing the values in an a List or IntArray and generate cnt straight away it won't pass test 13, with significant slowdown on test 12. Optimization is a fickle business...
 » 5 years ago, # | ← Rev. 4 →   0 F: Did you include complexity of choosing pair in the final complexity? In my solution, it raises a factor of $k$ in a determined way. If we are given such pair, mine works in $O(2^{2k} + kn)$. For each prime in at most $2k$ primes, choose an element that kills it and is not selected. Now we have at most $2k + 2$ numbers to consider. Simple bitmask results in $O(2^{2k})$.Edit: It is wrong and test cases are weak :). There are $O(k^2)$ numbers to consider. Another way: $dp[mask]$ is the earliest time to reach $mask$ will result in $O(k2^{2k})$.
•  » » 5 years ago, # ^ |   0 Number of pairs to check is constant
 » 5 years ago, # |   +16 The editorial is too concise to be understood. It's perfunctory.
 » 5 years ago, # |   +6 please anyone explain div1 D how take base condition and How do we perform transitionss?
 » 5 years ago, # | ← Rev. 2 →   0 For Div2E/Div1C, Can someone please help with a formal proof for always having at least n matching or independent set?
•  » » 5 years ago, # ^ |   +1
•  » » » 5 years ago, # ^ |   +8 Thanks!
 » 5 years ago, # |   0 problem c did the same thing and got WA during the contest
 » 5 years ago, # |   +3 div2D (div1B) is easier than div2C (div1A), and not only for me.
 » 5 years ago, # |   +6 Um_nik, sir why there aren't any solution in the tutorials? I mean one could have a better understanding of the your tutorial after looking at a solution implementing the same idea as provided in the tutorial, I guess.
 » 5 years ago, # |   +5 In Div1-F, You don't need to randomize the algorithm for choosing two numbers from different groups. If $n \geq 10$ and there is a solution, then there is also a solution in which the first number is in a different group from one of the next $9$ numbers, so you only need to check these $9$ pairs. This is true because otherwise, all $10$ numbers would need to be in the same group, but then you can just remove one of them because $k=9$.
•  » » 5 years ago, # ^ |   0 You don't need to, but it is faster
 » 5 years ago, # |   +6 For Div1 E, O(n^5) seems to be too expensive to pass. Can anyone explain why it would fit into the time constraint?
•  » » 5 years ago, # ^ |   0 Use pragmas
•  » » » 5 years ago, # ^ |   0 Is it ok for u to elaborate more?
•  » » 5 years ago, # ^ |   0 $50^{5} = 3.125 \cdot 10^{8}$, how can it be TL? Moreover, it is divided by 6 because left border is smaller than right and similar things.
•  » » » 5 years ago, # ^ |   0 I would say that 10^8 is a pretty dangerous bound.... Plus is it ok for you to explain why this number is devided by 6? I know it is pretty intuitive for you but it is kindda hard for me to see.
•  » » » » 5 years ago, # ^ |   +13 $10^{8}$ is nowhere near dangerous.If we are trying all $x, y, z$ such that $1 \le x \le y \le z \le n$, there are ~$\frac{n^{3}}{6}$ such triplets.
•  » » » » » 5 years ago, # ^ |   0 Thanks for explaining, that helps a lot!
 » 5 years ago, # |   +3 For problem 1198A — MP3: First, I sort the distinc numbers array and I use binary search to find out how many distinct numbers we should keep exactly. We know that these numbers must be consecutive so I use prefix sum to get the answer. https://codeforces.com/contest/1199/submission/58250549
•  » » 5 years ago, # ^ | ← Rev. 2 →   +1 Can you explain your code after you've assigned the n*ceil(log2(i)) to arr[i]?What is savNum? Can you explain that line?
 » 5 years ago, # |   +8 I found this guy flashmt use an algorithm with $O(n^4)$ in this submission 58039307. I had a hard time finding out why it is correct, and finally, I found it could be hacked by this input 9 ......### ......### ......### ......... ......... ......... ###...... ###....#. ###...... The output should be $7$ while his output is $9$.
•  » » 5 years ago, # ^ |   0 Yeah, my solution is wrong and it was already hacked here. Sorry for wasting your time trying to understand it :(
 » 3 years ago, # |   0 can anyone tell me in DIV2E/DIV1C how to greedily do matching stuff.is there any algorithm which i need to learn in order to solve this.Thanks for reading out :)