Codeforces Round 1068 (Div. 2) Editorial

Revision en2, by paulzrm, 2025-12-05 19:57:06

2173A-Sleeping Through Classes Idea & Solution: HHH666666

Solution:

2173B-Niko's Tactical Cards Idea & Solution: HHH666666

Hint 1:
Hint 2:
Solution:

2173C-Kanade's Perfect Multiples Idea & Solution: paulzrm

Hint 1:
Hint 2:
Solution:

2173D-Taiga's Carry Chains Idea: chen_zida Solution: paulzrm

Hint 1:
Hint 2:

Solution:> When $$$k \geq 32$$$, we can, at each step, add the smallest $$$t$$$ such that adding $$$2^{t}$$$ to the current $$$n$$$ produces a carry. After $$$k$$$ such steps, $$$n$$$ will become a power of $$$2$$$, and the answer will be $$$\operatorname{popcount}(n) + k - 1$$$.</p><p>Now we observe that the total number of carries in the end is $$$\operatorname{popcount}(n) + k - \operatorname{popcount}(n')$$$, where $$$n'$$$ is the final value of $$$n$$$ after all operations. To maximize this quantity, we want to minimize the final $$$\operatorname{popcount}(n')$$$.</p><p>To this end, let $$$dp[i][j][c]$$$ denote the optimal value we can obtain after processing the $$$i$$$ least significant bits, having used $$$j$$$ operations in total, where $$$c \in {0,1}$$$ indicates whether there is a carry from the $$$(i-1)$$$-th bit.</p><p>For the $$$i$$$-th least significant bit, we have two options: either select this bit (i.e., use one operation on this bit) or not select it.</p><p>Let $$$n_i$$$ be the $$$i$$$-th bit of the original $$$n$$$, and let $$$t_i$$$ be the sum at this bit after adding everything in. If we select this bit, then $$$t_i = 1 + c + n_i$$$; otherwise, $$$t_i = c + n_i$$$. From $$$t_i$$$, we can determine whether this bit produces a carry to the next position (the next carry is $$$c' = \lfloor t_i / 2 \rfloor$$$) and whether the $$$i$$$-th bit of $$$n'$$$ is $$$1$$$ or $$$0$$$ (the resulting bit is $$$t_i \bmod 2$$$), which allows us to perform the DP transition.</p><p>The time complexity is $$$O((\log_2 n)^2)$$$.</p><p></spoiler></p>

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en10 English paulzrm 2025-12-05 20:53:31 65
en9 English paulzrm 2025-12-05 20:41:41 531
en8 English paulzrm 2025-12-05 20:39:20 183
en7 English paulzrm 2025-12-05 20:26:30 1 Tiny change: 'ummary="Bounus">\nThe' -> 'ummary="Bonus">\nThe'
en6 English paulzrm 2025-12-05 20:13:28 1 (published)
en5 English paulzrm 2025-12-05 20:12:50 5179
en4 English paulzrm 2025-12-05 20:07:37 786
en3 English paulzrm 2025-12-05 20:02:36 3464
en2 English paulzrm 2025-12-05 19:57:06 3063
en1 English paulzrm 2025-12-05 19:56:28 9541 Initial revision (saved to drafts)