Editorial for WC '18 Finals S3 - Screen Time
Submitting an official solution before solving the problem yourself is a bannable offence.
We'll define a type- scene as one excluding actor . Let be the total number of type- scenes, and be the number of type- scenes included in the chosen subset. A subset is valid if and only if the following hold:
- , for each ,
- (equivalent to ), and
- (equivalent to ).
The number of different subsets with a given set of values is equal to the product . Before going further, let's consider how we can efficiently evaluate choose values in general (modulo a prime such as ). We'll first let be the modular inverse of for prime modulus , which is equal to .
may be evaluated in time using either exponentiation by squaring or the extended Euclidean algorithm. Then, we have:
If we precompute and for each between and , inclusive, then we'll be able to evaluate any necessary choose value in constant time. Now, let – in other words, the number of size--or-greater subsets of type- scenes.
Note that , meaning that we can precompute for all possible pairs in by iterating downwards through the values.
Let's consider fixing the number of type- scenes in the chosen subset. For a given , there are subsets of type- scenes such that is satisfied, and similarly subsets of type- scenes. Therefore, the total number of valid subsets which can be chosen with a given is , which can be added up over all possible choices of to yield the final answer.
Comments