![](/style/images/good.png)
![](/style/images/bad.png)
Codeforces Round #817 (Div. 4) Editorial
source link: http://codeforces.com/blog/entry/106478
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.
![In English](http://cdn.codeforces.com/s/64929/images/flags/24/gb.png)
Thanks for participating!
Idea: mesanu, MikeMirzayanov
Idea: flamestorm
Idea: flamestorm
Idea: flamestorm
Idea: mesanu
Idea: MikeMirzayanov
Idea: mesanu
![paperclip-16x16.png](http://cdn.codeforces.com/s/64929/images/icons/paperclip-16x16.png)
I didn't even think that Timur is lexicographically in order. What a brilliant solution! Edit: It isn't, but it's still an interesting solution to think of. |
-
-
i... totally knew that, good reading comprehension, well done, you passed the test
20 hours ago, # | Problem D can also be solved in O(n) using two pointers |
-
Can you give your solution here it would help
-
here if you need explanation feel free to ask
-
Hello, I saw your solution but I didn't understand this line . What is it for > for (k;k<=n;k++) ans[k]=s;
-
let's suppose that it was already optimal like RRLL so in the line you mentioned it just sets the remaining indexes (which could not be covered in while loop cuz of being optimal) they will just get the previous value as we will not be changing them...
-
-
-
-
What is two pointer approach... Can you share some resources from where I should learn... It would be a great help
-
Two pointer is basically using two indices to traverse through an array on the basis of some condition that you can apply on both the pointers(pointing to a particular index), like in the D part of the question we take one pointer at very start and one pointer at very end of the array and then we can check if we got a left viewer with first pointer then changing it to R will give a better score till n/2-1 and checking the same thing for the right pointer for the right side viewer till n-n/2, we can do this till left pointer is less than right pointer.
To understand two pointers you should try solving problems for it instead reading about it, this link will work for basic problems Two pointers and problems on it
19 hours ago, # | Why is problem A O(n)O(n)? You check if n=5n=5 in O(1)O(1); If it is, then sort the string which in this case will always have length n=5n=5 so sorting and checking is done in O(1)O(1) (since the length is upper bounded). So overall O(1)O(1), or am I missing something? |
problem G: topic 1Regardless of your correct answer, when you choose some elements and take their XOR, then the value will be equal to the XOR of the remaining elements. Why? Answer topic 2There exists a randomized solution. Explanation topic 3For 3≤n≤63≤n≤6, the answers are provided in the sample, so let's use them as a prefix.
After that, add (100,101,102,103,…)(100,101,102,103,…) until the length of the sequence becomes nn. (note that the length of added sequence is a multiple of 44 ) Then, you can get a correct answer. Why? |
19 hours ago, # | The latex for 230230 is bugged in the tutorial of problem G. Aside from that, problem G is a really cool problem! |
19 hours ago, # | For anyone who is finding the solution of problem F, hard to understand/code, can take a look at my solution using DFS 170297341 |
18 hours ago, # | D can be solved using two pointers. The main idea is that the first half of the line should look to the right and the second half to the left. We keep two pointers l and r on both ends and recalculate the sum whenever we encounter a position that needs to be changed. |
18 hours ago, # | Can we solve problem E using binary search? |
-
I did it this way because I didn't know about 2d sum prefixes. You need to keep a sorted 2d array, and then another 2d array of sum prefixes for 1..1000. Then you do two binary searches on the ranges to get your start and end.
It was slow but I passed using Go at 3500ms.
18 hours ago, # | Good contest, got sidetracked by D by trying to use two pointers. Your solution is much more elegant. |
Weak pretests for A , so many solutions got hacked. |
17 hours ago, # | How to write the code for Problem G with the alternate tutorial, I am unable to understand the approach |
Simple implementation for problem G
|
Problem F can be done using Surprise ! |
I had school so I wasn't able to do the contest, however I've solved them all and I present my solutions. They may or may not be worse quality than the official editorial. A B C D E F G |
-
tgp07 Excellent editorial, better than official one! Could you please tell me if there is a way to solve E under the same time constraints for tighter dimensions of the rectangle say 1e5 or 1e9 or even higher?
13 hours ago, # | |
-
Take a look at Ticket 16132 from CF Stress for a counter example.
13 hours ago, # | My first contest solving more than 1 problem :) I was excited to realize I could use a max heap to solve problem D. |
11 hours ago, # | Can anyone tell me a testcase where my submission 170342106 is failing for problem E? |
-
Take a look at Ticket 16131 from CF Stress for a counter example.
10 hours ago, # | What's hack ??! In the verdict of my submission it's written as hacked but earlier it was accepted any one care to explain what this hack is ??! |
10 hours ago, # | Damn. I was not getting what was going wrong in the first question. Used a if condition, which updates a count and individually checked the letters with T i m u r. But, it gave me wrong results. If i had not lost time on this, 5 questions were quite easy to do |
10 hours ago, # | When will my rating appear, yesterday was my 1st contest. |
-
For div2, preliminary ratings are updated in 2-3 hours. For education rounds/Div 3/Div 4, we have an open hacking phase which lasts for 12 hours so yeah, expect waiting for atleast 18 hours.
-
bro I am new here.Can you tell me what is this open hacking phase?
-
In div3/4 and Educational round, we have an open hacking phase for 12 hours. This means you can view others' code and find a test case where their code fails. If you hack their solution, the system will use this test case provided by you after these 12 hours during the system test (after which we get our final result, I hope you know the difference between system test and pretests). Hacking others won't give you extra points in the Edu round or Div 3/4. The only purpose of Open hacking phase is to promote hacking others' solutions and to understand others' writing styles. Hacking others will give you extra points in Div 2/1. To know more in detail, please use the codeforces search box. Searching is a good habit when on the path to becoming a competitive programmer. All the best!
-
-
Hey!, can someone help me up solving question F, My logic for the solution was that for each * there can be only and only 2 '*' neighbors in all 8 directions(if a cell exists there) no more, no less than that. But it fails on test no. 4, 69th ticket. can someone help me find a test case where this fails. WA link — https://codeforces.com/contest/1722/submission/170290140 Any help would be very appreciated. |
9 hours ago, # | 1722A - Spell Check Hacking not done properly, go through it once |
8 hours ago, # | My idea for G : XOR of 4 consecutive numbers starting from 0 is 0. 2^20 is greater than 2e5 which gave me sufficient power of 2's to play with. |
8 hours ago, # | for problem G for n = 5, the solution: 0 1 33554433 2 33554434 is valid or invalid??? |
My code for C using sets concepts in maths.
|
Is it only Me or anybody else also noticed that F was comparatively easy E for those who till now havent encountered problem based on 2-D PREFIX Sum . I am feeling very frustrated as I spent more than one hour on E and also during the contest F have least successful submission so I just dont focused on F |
7 hours ago, # | problem D can also be solved in O(n) time using two pointers using a greedy approach. in the first half of the string, we can get better answer by converting the leftmost 'L' to 'R' and in the second half of the string, we can get better answer by converting the rightmost 'R' to 'L'. link to my code — 170257607 |
6 hours ago, # | Alternate solution for Problem G: |
6 hours ago, # | On Problem 1722B Colourblindness I had the same Approach But still got WA on test case 3
|
6 hours ago, # | what is the use of greater() in the sort function of the D problem? |
5 hours ago, # | I solved 3 problems but my rating doesn't change. my rating point is still 0point |
I solved problem G quite differently from the editorial method utilising the property that XOR of consecutive numbers x and y is always 0 when x is an even number (if you didn't know this, it's easy to see why, by taking a few consecutive numbers and looking at their binary representation). Let set a and b represent respectively the set of numbers at even positions and the set of numbers at odd positions. Then we break solution into 4 cases depending on the remainder of n on dividing by 4. Case 1.) n%4 = 0 Case 2.) n%4 = 1 Case 3.) n%4 = 3 Case 4.) n%4 = 2 I think some of the cases can probably be combined for a simpler solution. Please let me know in the comments. Not so elegant and repetitive implementation : 170369765 |
In E, I'm getting MLE if I put prefix array in the heap memory, but the solution passing when I put the prefix array as a global array. Why is that so?
|
4 hours ago, # | A much simpler (in my opinion) and more readable solution for |
Another way to solve F: L-shapes: ref: https://codeforces.com/contest/1722/submission/170380611 1)Firstly for all 2x2 subgrid that contain L-shape, check whether its surrounding has any '*' in it, if so, then the ans is NO. [except for the corner along void position(exactly one such position) of 2x2 grid , ...# 2)Now the only problem is, there can also be any other shapes than L-shapes. To find that, |
2 hours ago, # | Can somebody explain solution E, I have never seen use of prefix sum like this. I dont quite get it what thay have exactly done here |
-
suppose you have a data structure which stores 2D-prefix sums, such that sum of rectangles with height <= H and width <= W = pref[H][W]
then if you wanna know the sum of areas of rectangles with height < Hb and width < Wb (condition — i) then that would equate to pref[Hb — 1][Wb — 1]
now say you want the sum of areas of rectangles which have height <= Hs and width <= Ws(condition-ii)
the rectangles which satisfy both condition i and ii is the required answer
for learning about 2D-prefix sums I would suggest going through the USACO guide, they have detailed and easy to understand content, https://usaco.guide/silver/more-prefix-sums?lang=cpp#2d-prefix-sums
2 hours ago, # | Why didn't my ratings update ? :'( |
78 minutes ago, # | did the same thing as mentioned in the editorial but is easier to understand. |
61 minute(s) ago, # | The first problem can be solved with a frequency array, by calculating the frequency of each character while taking inputs. Then check whether the frequency of each character of "Timur" is equal to one or not. |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK