MONSTER - Editorial

This can be solved using Parallel binary search and SOS DP too.

6 Likes

Can anyone please explain how to solve this problem using SOS DP? Thanks.

1 Like

Can someone please breakdown and explain this to me. I do not understand what the editorialist is saying. Because I’d love to know the solution of this problem as i was stuck on it during the contest.

2 Likes

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

This solution contains the code for 100 marks and is very well written along with comments…
Refer this if u are stuck…

Hope this will help.

8 Likes

Why the complexity is O(q+n\sqrt{q}), complexity of sum_overmasks is O(n\log n) not O(n) as is stated in editorial?? I’m missing something??

1 Like

Can we solve using tries?

An amazing tutorial on Sum Over Subsets DP can be found here.

sum_overmasks mentioned in the question is similar to SOS DP with the same complexity \mathcal{O}(n\log{n})
Doesn’t the complexity mentioned in the editorial miss this term - \mathcal{O}(n\log{n}\sqrt{q}). Or am I missing something? Even by altering the blocks size I couldn’t make sense out of the \mathcal{O}(n\sqrt{q} + q) complexity.

2 Likes

can anyone explain me why we are doing & with input of x

No not able to view the solutions

can you please explain?

1 Like

What is SOS DP?

SOS DP please … I am reading again and again that blog and but not get it

2 Likes

Sum Over Subsets - Dynamic Programming

1 Like

For each monster we can find out the query number at which they get killed using binary search and a DS which supports two types of query 1. add number y to subsets of x , 2. find the value of index x. (DS : Programming Problems and Competitions :: HackerRank), both of these queries can be handled in (log(n))*sqrt(n).

2 Likes

But if we binary search for each monster then it will be n*(qlogq(logn)*sqrt(n)). So we can improve this solution by removing simple binary search for each monster and using parallel binary search for all of them at once. Complexity: qlogqlognsqrt(n) .(parallel binary search: Parallel Binary Search [tutorial] - Codeforces)

2 Likes

can you please explain the second part of the hackerrank problem(how to count when the number of set bits is > 8 (i understand the first part of it i.e. all the values with set bits > 8 but for didn’t get the idea for < 8.

They are saying : “to count the numbers X that doesn’t satisify X and S = X we flip the digits of S (change every 0 to 1 and every 1 to 0) (note that S become to have at most 8 1-bits)
then count the numbers X that have at least one common 1-bit with S by inclusion - exclusion principle”

How you guys think that it will be done using sqrt decomposition? I gave it one day thinking of doing it using BIT.

PS: I love BIT

I agree - sum_overmasks is O(n \log n).

If block size is set to \sqrt \frac {q}{\log n} then perhaps time can be O(q + n \sqrt{q \log n}).

There is a question and answer discussing further.

1 Like

@john_smith_3 I believe you meant “If number of blocks is set to$\sqrt \frac {q}{\log n}$ then …”

time complexity would surely be O(sqrt(q) * (nlog(n) + sqrt(q)) ) if" sos dp " applied… as sqrt(q) for each block and nlogn for sos dp and in case killed , sqrt(q)…