

Codeforces Round #877 (Div. 2) Editorial
source link: https://codeforces.com/blog/entry/116995
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

9 hours ago, # | fast editorial! |
9 hours ago, # | very observational tasks....found c easier than a and b |
-
What's your output for 3 7 ?
-
although n,m>=4.
i think there is no solution for 3 7.
9 hours ago, # | difficulty difference of C and D are so Huge |
-
I can't even solve C :(
-
i have solve C before A.
-
I spent about 1.5 hours, but I cannot come up with any ideas :(
-
-
9 hours ago, # | Fast tutorial |
9 hours ago, # | fast editorial!! |
9 hours ago, # | Good contest and fast tutorial! But I can only solve one problem. |
-
hope u will do better in upcoming contests.
-
Thank you for your encouragement! I'll keep up the good work! I hope I can complete two questions in the next competition.
-
9 hours ago, # | fast editorial! |
9 hours ago, # | fast editorial! |
9 hours ago, # | I've had this argument with quite a number of people, but can you explain how you can approach C without brute forcing random patterns? |
9 hours ago, # | A good idea about solving problem D! I didn't expect the implementation of D to be so simple. |
9 hours ago, # | I found it cool that problems were not that standard, unlike usual div2s. |
-
Please show me a recent div2 that had "standard" problems.
9 hours ago, # | Short solution of A — E. Impressive |
9 hours ago, # | I enjoyed solving C most, it was a nice problem ! |
9 hours ago, # | Hit or miss forces |
9 hours ago, # | Almost solved E once again :(. Didn't notice that you don't need the values of array to count . Enjoyed the round, although I can see there are not so many people who have the same feelings |
9 hours ago, # | Anyone please help me out how to solve B and C questions in Div2. I got stuck many times in it. I had practice many questions but still am facing this issue. |
-
I had exactly the same problem (I still struggle with 3 sometimes), I suggest you solve problems from other websites especially leetcode. Also learn about prefix arrays,modular arthimatic and the very basics of DP and Graphs. Good Luck :)
9 hours ago, # | Is D well known trick? Why so many ACs... |
8 hours ago, # | Was I the only one to submit a brute-force recursion-with-backtracking solution for problem C? The worst-case time complexity is high, but it runs fast in practice because the problem is not very constrained. |
8 hours ago, # | Perfect editorial |
8 hours ago, # | Is it just me who enjoys Ds that are more algorithm and implementation heavy and not Ds that are like "because math something something cout << i-am-clown is always the correct answer" |
-
I too enjoy not thinking and getting my way through life as such. Unfortunately, this is often not possible.
-
based reply, honestly these people make me so mad, they just dont want to think, and then get annoyed when problems need you to think
-
Is there any problem that doesn't require you to think?
-
i think you know what i meant "needs you to think".
div2 abc problems that wud need ds would definitely need you not to think. (maybe if using easier ds)
I cant find a segtree problem fit for div2C difficulty aside from the trivial ones.
the core of the issue is : you cant have easy problems with data structurs because beginners should not be expected to have much knowledge of them. as maroonrk puts it, a problem should have thinking >>> knowledge. I would like to see a div2C in a 6 problem contest which uses ds and still follows that above principle
-
-
-
7 hours ago, # | Can someone please explain why this brute-force idea for A is incorrect? 0) if there is a negative integer that is obviously the answer. 1) insert all the elements in the array in a set. This set keeps track of all the elements which is impossible to get through the absolute difference of any 2 elements in the array. 2) Use nested for loops(n^2) and iterate through the array(not set) and check the absolute difference of every 2 elements in the array. If this absolute difference is present in the set, remove this from the set. 3) the element still remaining in the set, this must be one of the possible answers because of the fact that this element was impossible to get through any 2 elements' absolute difference. code link: https://codeforces.com/contest/1838/submission/208442311 |
-
hello,
first of all — set is not good thing if you have equal numbers.
second, you should check in your solution that removed element is not the one of the elements that you have considered as a difference.
-
ooooooohhhhhhh right, thanks a lot. I was breaking my head for over an hour.
thanks, a lot. That wrong submission cost me 200 ranks :(
edit: the brute force got accepted with a single-line fix. :)
-
Here's my thought process for ABC, hopefully it helps people understand how to come up with the solution. Sometimes it seems unintuitive but it is possible. A: We notice that negative numbers are abit sus from the sample testcases, how come theres only 1 or 2 negative numbers? Then realise because we are taking absolute difference the rest of the numbers are positive, so negative numbers can only appear at the very start => meaning, if we see a negative number we just print it. Else, there is no negative numbers, what to do? If theres no negative numbers, because we are taking absolute difference we can just take the maximum value in the array, as we can only get smaller values in the future by taking absolute differences. Therefore: if min < 0 print min, else print max B: Ok we want to minimise the number of permutation subarrays => What is the minimum value? Can we always get 1 and [1...n] as the only permutations? Ok idk if its possible, let me check the testcase: It seems that this is always possible after checking all the testcase. Therefore, we want only 1 and 1...n as the permutations, how to do so? See that if we place 1 and n beside each other, it may be good because every subsequent subarray afterwards that contains [1,n] will never be a smaller permutation. However we see from the testcase that ...2 1 n is still bad, because we only need 1 and 1...n as the permutations. 2 is pesky, so let us place it away from 1 so that we can never get 1,2 as a subarray. Ok how to do so? realise that 1, n, 2 and 2, n, 1 will be correct, so let us just make this pattern and we can ignore the rest of the subarrays. We can ignore the rest because we will always have [1,n] together without any other permutations formed C: Constructive, seems that many people are able to solve in the contest => Solution must be quite simple, aka spot the pattern or trick and the rest will fall out. Ok, seems that we need to find a simple solution, do not tunnel vision into the first approach you have! Try out a few different approaches and see which one is the most simple to implement and easier to extend: For example, I tunnel visioned into grouping all the even / odd numbers together, and then at the border of odd / even we need to make everything 1. Seems complex, so lets discard that idea (unfortunately I tunneled too hard into random ideas). Ok let us think of a very naive solution, for 4x4, we can try out 1 2 3 4 ... 14 15 16. Wow seems like it works, is it simple? yes, is it easier to extend? Hopefully. Realise that for 5x5 this doesnt work. Key insight: Think of why it doesnt work instead of just trying out other random approaches. Ok it doesn't work because the next row is +m, and m is 5. Ok so how to make the rows better? If we just think of why it doesn't work, can we possibly modify or extend this idea to make it work? Turns out, if we make the rows +2m +2m and so on, it will not be prime. So: we can place the even rows at the top and the odd rows at the bottom to make sure this difference is indeed > m and a multiple of m. Hope this helps |
-
the point of "Don't tunnel vision into the same approach" is really important. I was lucky to have got the right approach on the first try, usually I tend to stick to one idea a lot ;)
-
Unfortunately I had all sorts of weird ideas like boxing the last column into the last m guys, zig zag, spiral, diagonals, grouping even odds together and making the borders 1, trying odd / even in a way that if n,m is odd we make the border zigzagged, making +4 +4 +4 and so on. If only I thought of simpler ideas I might have gotten it during the contest. At least I learnt something new I guess.
-
My solution for 1838D - Bracket Walk: Observation behind the approach Any even length sequence of the form Also, the prefix and suffix string should be exactly of the form k* Implementation: Maintain two sets
To check the correctness of bracket sequence
Time Complexity Here's my solution using this approach, although I wasn't fast enough to implement during contest time: 208516428 |
7 hours ago, # | Hey .. Can someone suggest me a video to understand D , having a hard time warping my head around it |
-
I would suggest first try to solve few regular bracket sequence related easy problems. That will build your logic, then try to solve this problem.
Editorial's solution as well as solution proposed by Spartanlord are good ones. I am sure u will be able to understand one of these solution once u build some logic.
way to go ...
4 hours ago, # | Hi, is there to way to download the test data for problem C? Pretty sure the code should work for all inputs but it keeps finding an error, I often make some stupid mistake in code but already removed 3 problems from it and can't find another. |
-
The problem is that your code (in some cases) swaps rows and columns. For example on test
The code should output a grid with rows and columns, but your code outputs the following:
Since the checker doesn't care about whitespaces (spaces, linebreaks etc.) but it is expecting integers per line, your output gets interpreted as
which is obivously wrong.
3 hours ago, # | during contest: WTF is this, I hate this contest. After reading editorials : what a beautiful problems. How much more stupid I can be !!! |
88 minutes ago, # | can someone explain solution for c |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK