Unofficial editorials December Long challengr Part 2

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:

Your calculation for e is wrong.As its not necessaray that N will be a perfect square.So just check if e<=n.
Also if u get AC , share your code.Since i was getting tle with this approach in c++.

Or more simple write e=min(e,n)

Isn’t it taking too much time? My O(N^2) solution ran in 0.47 seconds (in java). Anyways, the solution which works is fine. :smiley:

I wrote same brute force in c++ all i could get is 50 pts why this one passed all -_-