SCHEDULE - Editorial

I am getting NZEC error in this code.
https://www.codechef.com/viewsolution/13067855
can anyone explain why i am getting this error?

My code is working in 3/9 case can someone help me with this .
code link-> https://code.hackerearth.com/ec26cap?key=8873a98d212090ee34b470913e133bfb

Alternative Solution: Maintain a set of all original segments.Think of ‘k’ as total resources you have to allot to these segments to minimise the maximum contigous same bits.One can calculate the closed form for maximum subsegment size of the original segment when ‘x’ resources are alloted to the segment.The first element always corresponds to the original segment having maximum sub-segment size.At each iteration we allot one more resources to the first segment and calculate its new position in the set.The procedure terminates when k=0 .
Complexity : O(n*logn)

2 Likes

@ajaman13 … There seems to be no code out there.

nice editorial…

if k is greater than (n+1)/2 then will the answer be 1?

Yes @aminuteman . For any given sequence, for the answer to be 1, the minimum number of moves required will always be less than or equal to half the length of the sequence. So, if k is >(n+1)/2 , we will surely be left with one or two excess moves even in the worst case. It can also be put this way - For the answer to be 1, there must be n/2 ones and n/2 zeroes (considering n is even, when n is odd, there will be an extra 1 or 0). So, to change the sequence so that answer becomes 1, at max we require n/2 moves or (n+1)/2 moves. Hope you got it.

I need the explaination for the editorialist’s solution’s [[Binary Search]] Logic. Thanks in Advance.

it can also be solved by checking for each answer ( not more than the length of longest segment ) …
if we are checking for an answer (say target) ,we try to reduce all the lengths of segments greater than our target by dividing it into n parts which will require n-1 values of given ‘k’(allowed flips).

n = length of segment / (target + 1)

if all the segments can be divided requiring not more than remaining k flips…then our target is achieved and we have the answer, otherwise we will check for the next target(i.e target + 1).

here is the link to my code

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

Wouldn’t an approach like the following work?

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

@padamchopra Can you explain your approach in words ?

Can someone tell me the error in my solution ? I have tried a lot but could not find anything erroneous . Please help !!! CodeChef: Practical coding for everyone

Please tell me error in my code. I tried a lot but there are always few test cases giving me WA.
https://www.codechef.com/viewsolution/13090588

Don’t Know which test cases did i miss help me with my code. CodeChef: Practical coding for everyone

for k>1 and less than n find the consecutive block length in the initial string put them in a container and keep them sorted. max value of the container split from mid like for 9 → 4,4 (111111111)–>(111101111) //pop 9 and push 4,4 into the container and for even in this way 8 ----> 3,4(11111111)—>(11101111) //pop 8 and push 3,4 keep it doing till you get the top value of your sorted container==l and keep the count of flips if flips exceed return false for the query of l else return true that we will be doing a binary search for l>1 . for l==1 do the same way as in the editorial compare with 2 possible solutions.when it ends you get the minimum value of l(maximum consecutive same bits) possible

@abx_2109 I have used almost same approach as yours still I’m getting 5/9 cases. can you tell me what is the problem with my code.
CodeChef: Practical coding for everyone.

Can Anyone please tell me whats wrong in my code and how to correct it?
here is my link -
https://www.codechef.com/viewsolution/13074954

@abx_2109 I have used almost same approach as yours still I’m getting 5/9 cases. can you tell me what is the problem with my code.
CodeChef: Practical coding for everyone.

I am still not getting why binary search is used here. As far as i know Binary Search is sued for searching element in an array. Can any one explain it more clearly?

@shibli786
Binary search is used to reduce the computation effort.If we know that a may be the possible answer then there is no use in checking for the numbers > a else check for the numbers < a . If a doesn’t satisfy then check for the numbers>a till u find a minimum value that satisfy it.

1 Like

This problem can also be solved without binary search. What you have to do is simply start from i = 1 where i is no of the continuous element appearing in the string. Then apply the concept of dividing partition by k+1 and check for all possible values of i and print the answer when count <= k.

Submission link: CodeChef: Practical coding for everyone