Please @only4 wait for some time. I have already mail this question to codechef and they replied me “we are working on this, and will post it as soon as possible, so please be patience”
And i think most of the question has already been discussed in this discussion session. If you still have any doubt in any question then please ask it individually.
Instead of waiting for editorials, I will advise you to ask the question on discussion forum. Because you will get the answer quicker, and will have a more meaningful engagement (I find discussing Q on forum better than reading editorials, cause its interactive and one can ask doubts).
So yeah, go ahead and ask the question you have doubts on, people will love to help
@ghost_pilot I used dynamic programming for this approach. Let us take the example of the given test case.
3 3
0 0 1 1 0 1 1 0 0
My approach was simple. For the first o2 elements i calculated the winner and then i started removing the first element in o2 and added the (o2+1) element. For eg:-
0 0 1 - Winner (0)
Now in the next iteration the first 0 will be removed and the next element i.e 1 will be considered.
Thus now the o2 elements selected will be 0 1 1. For this case the winner is 1. In the similar way start storing the winner for each iteration. This will take o2*o1+o2 time. Now after this array is computed, then use nested for loops for iterating over the newly computed array. Increment the current position by o2 and find if the number of times 1 occurs is greater than the number of times 0 occurs. If yes, break and print 1. Else in the worst case the complexity will be o2^2.
approach: prefix sum array
it is used here to calculate the contiguous sum of m elements
n = states
m = districts
if number of district for each state is 1 then just check if number of 1’s are greater than n/2
else
just take the sum of contiguous sum of m elements in the given array(here array ones[]) and check if the majority is 1 or not.
and increment the count (here variable c). in the last step we again check the majority of people elected from all the states(numg1>n2)
That’s a good idea but we should be aware of the true aim of a problem and what problem setter wants us to think. For a single problem there is a number of solutions exist but problem setter’s solution is the most optimal. As you know for lots of problems (for example CHAIRS from feb cook-off) the problem setter’s solution is of 30+(greater) lines, but all the other AC solutions are of just 15(less than) lines.
WAIT! Did you just provide said something and contradicted it in next line? If problem setter’s code is longer, how is it more optimal than the shorter codes? Am I missing something?
BTW-
Yes, problem setters thinking is quite important when you’re in the learning stage.
But after a certain time, you become professional enough to outsmart problem setters (depends strictly on you and the setter tho) and come up with even better implementations.