ARC224-- Participation Report
It’s me.
I participated in ARC224—. I solved 4 problems: A, B, C, and E.
It feels great to have a solid win in my first Rated ARC.
Problem A Attach 00
always ends in . This means we just need to check in order and output the first one that contains in its decimal representation.
We only need to check at most 100 multiples per case, and each has a maximum of 12 digits. Therefore, with , the computational complexity is approximately
Converting them to strings and using contains("00") is more than fast enough to pass within the time limit.
Problem B Adjacent Tiles
When arranged in an rectangle, the number of fully shared edges is
For a square with side length , the number of shared edges is
Since this is monotonically increasing with respect to , it seems best to first create the largest possible square.
So, let
Next, consider extending one side directly from the square.
If we let
we can first form an rectangle. The number of shared edges this rectangle has is
Let the number of remaining tiles be
If , we add a row of tiles to the side of the rectangle.
The first tile shares one edge with the rectangle, and each subsequent tile touches the rectangle and the previous tile, so the number of edges added when is . Adding this to the formula for the rectangle gives the answer.
In other words, the answer is
Problem C Ascending Labels
Initially, I tried an implementation thinking it was BFS, but it was a wrong approach. After rephrasing the conditions normally, I realized it should be DFS.
If we set the BFS distance as , there may be multiple adjacent vertices with a distance exactly 1 smaller. Since the problem requires that there must be exactly one adjacent vertex satisfying , this does not satisfy the condition.
Therefore, we construct a DFS tree rooted at vertex 1 and set the depth of each vertex on the DFS tree as .
The parent of vertex has a depth exactly 1 smaller, so it satisfies . Furthermore, in a DFS on an undirected graph, edges not included in the DFS tree connect ancestors and descendants.
There is no ancestor with a depth exactly 1 smaller than other than ‘s parent. Consequently, there is exactly one adjacent vertex satisfying .
Thus, simply implementing DFS is sufficient.
Problem D Angst for All Pairs
I really have no idea what’s going on. I couldn’t understand the meaning of the Japanese.
Problem E ABC|AB|A
I was fixated on deciphering Problem D for a long time, but when I happened to look at E, I felt sad because it was too easy. If only I had looked at this one from the start…
Read the string from back to front and push B and C onto a stack. When an A is read, remove elements in the following order:
- If the top of the stack is
Band the one below it isC, remove the completedABC. - If it doesn’t form
ABCbut the top isB, removeAB. - If neither of the above, remove
Aby itself.
The answer is the number of Bs and Cs that remain without being removed.
Closing
I like ARC quite a bit because it places more emphasis on problem analysis compared to ABC.
See you again.