This problem is actually just a textbook problem for Gaussian elimination. Following the statement, we can write equations of the following form:
\[\sum_{i = 1}^n (x_a [i] - x_0 [i])^2 = c\]
where \(c\) is the radius of the sphere. There are \(n+1\) such equations in total; we can subtract consecutive ones to cancel the constant, which builds a system of \(n\) equations. The final system:
Continue reading →Chinese original · English translation by Claude Opus 5.5
Looking at the constraints of this problem, you can think of bitmask \(DP\). Consider designing a state: \(dp[S]\) represents a set of women, where the size of the set \(|S|\) provides another piece of information. In other words, \(dp[S]\) represents the number of transitions for the set of women corresponding to the first \(|S|\) men. It is not hard to derive the following formula:
\[dp[S] = \sum_{(i, |S|) \in compatible} dp[S'], S' \cup i = S\]
Continue reading →Chinese original · English translation by Claude Opus 5.5
Consider recording the indices of each category's elements, then first put the smallest-numbered element of each category into a multiset, and then update the answer: each time, take out the maximum and the minimum and update with their difference, then update the minimum's index and toss it back into the multiset. If all the categories in the multiset have been fully enumerated, just break out of the loop and output.
Continue reading →Chinese original · English translation by Claude Opus 5.5
We notice that it can be optimized with a Fenwick tree, so the complexity here is \(O(n^2 \log n)\). Let \(g[i] = \sum_{i = 1} f[i, n]\), and consider the contribution to the answer. For a given \(i\), there are \(g[i] * (n - i)!\) ways to carry out the transformation, but note that these \((n - i)!\) include the cases where the transformation was already finished early, that is, the cases where we deleted valid elements from a valid sequence, and that definitely won't do. Consider inclusion–exclusion: the contribution is \(g[i] (n-i)! - g[i+1] (n - i - 1)!(i + 1)\), which represents the ways of choosing \(i+1\) valid elements among these.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem is DP + inclusion–exclusion, which happens to be exactly the type I'm not very good at. Let the state \(f[i][j]\) be “the number of ways in which, after considering the first \(i\) states, \(j\) colors are the same as the original (note that here, a different color is not what makes things essentially distinct)”. We can derive the formula:
Actually, this problem is a total freebie. We know the condition is \(x_l \text{ xor } x_{l+1} \dots x_{mid} = x_{mid+1} \text{ xor } x_{mid+2} \dots x_{r}\), but we can move terms straight across in this operation: because \(xor\) is its own inverse. Then, to make sure \(r-l+1\) is even, we just need to maintain odd and even counts at the ends of the Trie.
Continue reading →Chinese original · English translation by Claude Opus 5.5
You are given a tree with vertex weights and a bunch of paths; for each vertex \(i\), how many paths satisfy \(w(s,i) = weight(i)\)?
Sounds pretty nasty, right? Following the standard trick for this kind of tree problem, consider splitting every path into \((s \to LCA(s,t))\) and \((t \to LCA(s,t))\) and handling them separately. Let's first deal with the \((s \to LCA(s, t))\) kind: suppose we now want to know the contribution of the path \((s \to LCA(s, t))\) to vertex \(i\); then it must satisfy:
Continue reading →Chinese original · English translation by Claude Opus 5.5