ABC #215
AtCoder Beginner Contest 215
F - Dist Max 2
Approach: binary search
Binary Search is always an option! Unless you have to do things the hardest way.
G - Colorful Candies 2
Split the expectation into contribution over each color, then we have:
\[ \begin{aligned} E(X_k) = \sum_{c}1 - \binom{n- cnt_c}{k} \left. \middle / \binom{n}{k} \right. \end{aligned} \]
Notice that there are at most \(O(\sqrt{n})\) different \(cnt_c\). So the problem is solved in \(O(n\sqrt n)\) time.
H - Cabbage Master
let \(O\) be the set of all "1 cabbage order"\((ord, V)\) where \(V\) is the set of all acceptable brands.
By Hall’s marriage theorem, all the orders in set \(O\) can be satisfied if and only if
for all \(T \subseteq O\) , \(\sum_{s\in \cup V}a_s \ge |T|\) holds.
change the summation order and iterate over set of brands, we have
\[ f(S) \ge g(S) \]
for all \(S \subseteq V\) .
Where \(f(S)\) is number of cabbages, \(g(S)\) is number of orders.
\(\min {(f(S) - g(S))}\) is the number of cabbages eaten.
Find all valid \(S\), and calculate the number of ways when the snake only eats cabbages of brands in \(S\).
This can be done using an OR convolution and an inverse AND convolution.
1 | void solve() { |