2288A. Youmu Konpaku and the Duel, O(1) Solution

Revision en7, by koifishify, 2026-11-22 04:51:40

2288A - Youmu Konpaku and the Duel This solution involves the use of calculus to find the minimum in $$$O(1)$$$.

We start by recognising that charges must occur before attacks. Let $$$M$$$ be the total amount of moves:

$$$M=C+A$$$

After $$$C$$$ moves to charge, we reach a maximum attack power of $$$1+C$$$ (since we perform $$$+1 +1 +1 + ... C$$$ times). Then, we must make the minimum amount of attacking moves $$$A$$$ such that the total damage $$$ATK_{tot}$$$ is greater than or equal to the yokai's health $$$x$$$. That is:

$$$ATK_{tot} = (ATK) + (ATK - 1) + (ATK - 2) + ... + (ATK - A) \ge x$$$

Since our highest attack power is $$$1+C$$$:

$$$(C+1) + (C) + (C - 1) + ... + (C - A - 1) \ge x$$$
$$$(A+2)(C+1) - \frac{\left(A-1\right)\left(A\right)}{2} \ge x$$$

(using Gauss' formula)

$$$C\ \ge\ \frac{x+\frac{A^{2}-A}{2}}{A+2}-1$$$

Substitute back into our original equation:

$$$M = C + A$$$
$$$M = \frac{x+\frac{A^{2}-A}{2}}{A+2}-1} + A$$$
$$$\frac{dM}{dA}=\frac{2A^{2}+8A-x+2}{\left(A+2\right)^{2}}$$$

(product rule, rearrange)

Tags c++, maths, contest

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en29 English koifishify 2026-11-22 06:54:49 2 Tiny change: '\right)C\ +\ \frac{\l' -> '\right)C\ -\ \frac{\l'
en28 English koifishify 2026-11-22 06:13:08 0 (published)
en27 English koifishify 2026-11-22 06:03:14 36
en26 English koifishify 2026-11-22 05:56:03 42
en25 English koifishify 2026-11-22 05:54:51 114
en24 English koifishify 2026-11-22 05:53:43 575
en23 English koifishify 2026-11-22 05:49:54 1 Tiny change: 'range:\n$$frac{dM}{d' -> 'range:\n$$\frac{dM}{d'
en22 English koifishify 2026-11-22 05:49:23 13
en21 English koifishify 2026-11-22 05:48:09 41
en20 English koifishify 2026-11-22 05:45:37 59
en19 English koifishify 2026-11-22 05:41:04 69
en18 English koifishify 2026-11-22 05:39:48 1 Tiny change: 'C-2,\ \dot,\ C-\left' -> 'C-2,\ \dots,\ C-\left'
en17 English koifishify 2026-11-22 05:39:35 37
en16 English koifishify 2026-11-22 05:37:51 95
en15 English koifishify 2026-11-22 05:17:38 102
en14 English koifishify 2026-11-22 05:13:34 44
en13 English koifishify 2026-11-22 05:12:41 82
en12 English koifishify 2026-11-22 05:08:07 2 Tiny change: '}{2}}{A+1}+A$$\nProd' -> '}{2}}{A+1}-1+A$$\nProd'
en11 English koifishify 2026-11-22 05:06:08 294
en10 English koifishify 2026-11-22 05:00:00 161
en9 English koifishify 2026-11-22 04:56:30 19
en8 English koifishify 2026-11-22 04:52:52 51
en7 English koifishify 2026-11-22 04:51:40 173
en6 English koifishify 2026-11-22 04:46:50 106
en5 English koifishify 2026-11-22 04:45:01 126
en4 English koifishify 2026-11-22 04:43:01 12 Tiny change: ' is:\n\n$$(ATK) + (A' -> ' is:\n\n$$ATK_{tot} = (ATK) + (A'
en3 English koifishify 2026-11-22 04:41:43 242
en2 English koifishify 2026-11-22 04:36:46 309
en1 English koifishify 2026-11-22 04:30:58 292 Initial revision (saved to drafts)