103503A — Make Sum Great Again
Author: Gheal
Hint 1
Hint 2
Hint 3
Hint 4
Solution
103503B — Binary Search Search
Author: Gheal
Hint 1
Hint 2
Solution
103503C — Plates
Author: Gheal
Hint 1
Hint 2
Solution> Let <code>dp[mask]</code> be the minimum number of moves required to cover the first $$$\Sigma_{i=1}^k getBit(mask,i)*p_i$$$ slots with all plates of colours $$$c_1,c_2,\ldots$$$ where $$$getBit(mask,c_i)=1, \forall i$$$. Naturally, $$$dp[0]=0$$$.</p><p>Transitioning from $$$dp[mask]$$$ to $$$dp[mask+2^k]$$$, where $$$getBit(mask,k)=0$$$ can be done fairly easily. Let $$$pos=\Sigma_{i=1}^k getBit(mask,i)*p_i$$$ and $$$cntdiff(l,r,k)$$$ be the number of plates in the initial configuration $$$a_i$$$ which satisfy the following requirements: \begin{enumerate} \item $$$l \le i \le r$$$; \item $$$a_i \neq 0$$$; \item $$$a_i \neq k$$$. \end{enumerate}. From these definitions, the value of $$$dp[mask+2^k]$$$ can be computed using the following formula:</p> <center>$$$dp[mask+2^k]=dp[mask]+cntdiff(pos+1,pos+p_k,k)$$$</center><p>$$$cntdiff(l,r,k)$$$ can be calculated in $$$O(1)$$$ per query using prefix sums. Calculating the prefix sums has a time complexity of $$$O(n \cdot k)$$$. </p><p>Intended time complexity: $$$O(n\cdot k + 2^k \cdot k)$$$</p><p>Reconstructing the final configuration will also require an auxiliary array $$$prev[mask]$$$ — the last colour added to $$$mask$$$. </spoiler></p>