Hi all, Atcoder Beginner Contest 174 was today. I wrote an unofficial English editorial. Hope it helps!
A: Air Conditioner
We simply write an if statement.
Runtime: $$$\mathcal{O}(1)$$$.
B: Distance
We can loop through all the points, and test each one. To avoid potential rounding errors, it's simplest to check $$$x^2 + y^2 \le D^2$$$, so we can keep everything in integers.
Runtime: $$$\mathcal{O}(N)$$$.
C: Repsept
First, we simplify: if $$$k$$$ is a multiple of $$$7$$$, then we can look for a number like $$$1111$$$ that's a multiple of $$$k/7$$$. Otherwise, using $$$7777$$$ instead of $$$1111$$$ doesn't help us.
If you consider this as the $$$a_i = 10 a_{i-1} + 1$$$ modulo $$$k$$$, there is guaranteed to be a solution within $$$k$$$ steps if and only if $$$\mathrm{gcd}(10, k) = 1$$$. So we can check for impossibility using this fact, and then iterate through the choices otherwise and check them all until we find the smallest one that works.
Take care to test locally on $$$k=1$$$ specifically, it's easy to get this wrong with a loop.
Runtime: $$$\mathcal{O}(k)$$$.
D: Alter Altar
A few quick observations:
- At the end, we want a sequence that looks like RRRRWWWWWWW (some number of red stones, followed by some number of white stones, and one of these could possibly be zero).
- If we want to change a red stone's color and a white stone's color, this takes 1 step as we can swap them.
Now, we can simply try all values of the final number of red stones from $$$0$$$ to $$$N$$$ (let's call this number $$$R$$$). For a given value of $$$R$$$, the cost is given as
If we compute prefix sums to help us compute this, we can test one value in $$$O(1)$$$, so testing them all will run in time.
Bonus: this function is convex, so we can minimize it using ternary search.
Runtime: $$$\mathcal{O}(N)$$$.
E & F coming soon (still typing them up).
You can see my submissions here as well, if you prefer that to reading the code in the blog.
Thanks for reading! Let me know if you have any questions or feedback for me.