Unofficial editorials December Long challengr Part 2

I am also getting TLE with the square root decomposition technique in c++. In Subtask 3, just one test case(the first one) is getting passed and others are TLE. Please Help!

hi Taran,
I have done this in O(n) and my code run in less than (0.1)sec for all test cases.
Just see my code.I think my solution is most optimised than the above posts.

CodeChef: Practical coding for everyone

My solution for CHEFHAM: CodeChef: Practical coding for everyone

I LOL’ed hard after this passed.

6 Likes

Those who are getting TLE for CHEFEXQ, use normal array instead of an map/Hashmap. Map increases the time complexity by additional logn factor per query.

In order to set all index of certain block to zero during an update operation, instead of traversing whole array, first decrement all previous indices stored in block and then update the block( see code for further clarification.).

Here is my code getting TLE using map data structure.

https://www.codechef.com/viewsolution/16555697

Here is my code getting accepted after using array.

https://www.codechef.com/viewsolution/16555808

1 Like

taran give me some advice to solve medium hard problems on codechef

What’s wrong in my code…can anybody help me out, plz…

Here is my


[1]
  [1]: https://www.codechef.com/viewsolution/16560604

Thanks...

For CHEFHAM, I tried a different approach, I broke the array in subarrays of length two, now there can be two cases:

  1. Both the elements in a subarray are different, then just swap the elements
  2. If both the elements in a subarray are same, swap the position of this subarray with the nearby subarray.

Take care of the last element left for odd n.
Here is the link to my solution :


[1]


  [1]: https://www.codechef.com/viewsolution/16516552
1 Like

@taran_1407 can u post a link to your segment tree solution for chefexq

@taran_1407 thanks for the editorial. For the problem CHEFHAM, shouldn’t there a break after swapping the two positions in your code?

@taran_1407 I got a solution of CHEFEXQ got AC in brute force approach using numpy python library, how can it possible solution, plss help me!

I tried to do CHEFEXQ with BIT(fenwick tree) got 50 points can anyone suggest how can the query part be optimized to suit the problem.
here is the code.

This is my solution for CPLAY. CodeChef: Practical coding for everyone Can someone check and tell me why its giving Wrong Answer?

I made a observation for the chefham problem that if the array length is greater than 3 than there always and always should exist a array with hamming distance equal to the length of the array. I could not implement a solution for the same, I have now a thought about directly outputting a sorted array using check that the position does not match with the original array, if it does then it goes to a different array and this continues till there is no element left to output.
Any suggestions and is my observation regarding the hamming distance correct? Thanks

Hello, my approach was to divide the array into two sub parts where the first part contained elements with frequency 2 and the second part contained elements with frequency 1. Then checked if the 1st element of the new array is same as the jth element of the given array, if yes then increment j by 1, if no then pop that element, print and continue.

But I got TLE for the 1st test of the Subtask 3 only while 2nd one executes perfectly. Can anyone please help me why my solution’s getting TLE?

Code: CodeChef: Practical coding for everyone

Your solution to Problem CHEFHAM is great.
However, could you give me some hints why the solution guarantee to find the maximal Hamming distance?
Thanks

Great explanation! Thanks

And that too using Scanner for reading input? I can’t believe this. :frowning:

Nice way, Although i like getting an AC with an O(N^2) algorithm. :smiley:

Unbelievable, I too ran first solution brute force, which gave only 50 points.

Well, i guess this one is the simplest one. Because Segment tree, popular choice for such range query problems, didn’t work, atleast for me. If you solve it in a different way, feel free to share. :slight_smile: