Unofficial editorials December Long challengr Part 2

@taran_1407 I attempted the problem CHEFEXQ as you explained above

My Code:- Link to my code

Where am I getting it wrong? Please have a look at my code.

CHEFHAM can be solved in so many ways . The test cases were weak enough for hit and trial for obtaining the solutuion .
CHEFEXQ scoring was bit weird too . The most basic brute force solution of CHEFEXQ was able to fetch 50 points. THere was no need for three different scoring brackets .

Anyways thanks for the editorials . Keep up the good work Taran :slight_smile:

Thanks for the editorial.
Can we do CHEFEXQ with segment trees in any way?

Hey @taran_1407, used same method for CHEFEXQ but getting TLE. Doing Square_Root_Decomposition, storing frequencies in unordered_map, used lazy technique for update task, still getting TLE.

Here is MY CODE .

For the CHEFHAM I used a slightly different approach but got only 60pts because of one test case going wrong. Can somebody figure out where might I go wrong?

Here is my


[1]

I handled palindromes and non-palindromes separately.


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

For CHEFHAM I used the following approach. If n > 3 break the array into two subsequences of length greater than 1, each consisting of unique elements, and cyclically shift each subsequence. Otherwise cyclically shift the longest subsequence consisting of unique elements. All of this can be done in a single pass.

Solution.

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