AtCoder Regular Contest 224
Introduction
I participated in the AtCoder Regular Contestβ 224 this past Sunday. This was my first full-solving an ARC live, and I felt the problems were very educational.
A. Attach 00
Problem. Given a positive integer (), find the smallest positive integer such that is a multiple of , and the base-ten representation of contains the substring 00.
Analysis. At first glance, there doesnβt seem any clear path towards computing the answer. I thought that instead of trying to guess constructions, I should try to prove some results.
First, I need to show that such an even exists. In fact, always ends in 00, so such an exists, and the upperbound is .
Now I see that there are only candidates to test: , so each test case can be solved in at most operations, so the brute-force algorithm is fast enough even over testcases.
Note that if we keep track of the current length of the base-ten representation, we can avoiding the log factor for every integer and achieve a solution with about operations per testcase, but this is not necessary for this problem.
B. Adjacent Tiles
Problem. Place () unit squares on a plane so that they do not overlap. What is the maximum possible number of pairs of different tiles that share one full side?
Analysis. Since can be up to , the solution is likely a simple math formula.
Indeed, with some greedy guessing and contradiction logic, it is possible to prove with a lemma that the answer is
C. Ascending Labels
Problem. Given a connected simple undirected graph with vertices and edges (, ). Assign an integer () to every vertex such that and for all vertices , there is exactly one vertex adjacent to satisfying .
Analysis. We first think about the following question: βwhat kind of structure has the required property?β By thinking about this question, we recall that a tree has the property that each vertex besides the root has exactly one parent, and if we can assign to the depth of some tree describing the edges, we are done.
What is a tree we can make from a graph? A DFS tree! It is not hard to show that a DFS tree satisfies the given properties. Therefore, for each vertex , we output the depth of in the DFS tree rooted at for the given graph. The time complexity is .
D. Angst for All Pairs
Problem. There are () cards, numbered through . Initially nothing is written on any of the cards. Writing a number on a card incurs a cost equal to the number of digits in the decimal representation of . Find the minimum cost required to make sure that for every integer pair with (), there exists a card containing exactly one of and . If this is impossible, output .
Analysis. In my opinion, this problem is quite difficult to solve purely by staring at it and trying to prove a magical answer. It is more intuitive to play around with some examples.
After playing around with various examples for a while, I discovered that we can skip one of the numbers. Then, we should put one number on each card first. If there are more, put a number on two cards such that this pair has not been selected for a βtwo-cardβ level. Then do the same for three, four, β¦ until we have no numbers left. The game is impossible if we still have numbers left after exhausting the level of βwrite to every card.β
For level , there are spots to put a number. Therefore, we can put at most
numbers in total. The answer is if and only if .
Now suppose . We will execute the greedy algorithm described above for (place the larger numbers first).
The time complexity for this simulation is in , but it is a bit hard to show.
E. ABC|AB|A
Problem. Given a string () consisting of A, B, and C, you can perform the following oepration zero or more times: βChoose a substring of that is either A, AB, or ABC, and delete it.β Find the minimum possible length of in the end.
Analysis. I was surprised that I solved this problem in five minutes. The problem reminded me of ideas in DFAs (Deterministic Finite Automations).
The idea is to keep track of βhow close we are to being able to delete a substring.β We can do this by defining a DFA with states being the suffixes of the deletable substrings.
We will process the characters of in reverse order. We will define a DFA with the following states: , representing the current suffix we see. The transitions are straightforward: , , . Let ans be initially. Whenever we reach one of the deletable substring, we move back to and add subtract the length from ans, and whenever we reach a string that can never be extended leftwards to match a deletable substring (i.e. not part of the transitions), we go back to . We can show this greedy algorithm is correct by induction on the suffix of . The time complexity is .
F. AND/OR
Problem. See official statement.
Analysis. This problem has some nice ideas about the prefix sums of binomial coefficients.
This will take a while to explain, sorry. See official editorial for their solution, which was the same as mine.