Open In App

Contest Experiences| AtCoder Regular Contest #156

Last Updated : 16 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This was a contest organized on the AtCoder platform on February 18, 2023 and it consisted of 6 questions that were to be solved in a time frame of 120 minutes from 5:30 PM to 7:30 PM (GMT+5:30).

Prizes/offers: It was a rated contest, so no such prizes were offered.

Link of the Contest: https://atcoder.jp/contests/arc156

Overview of the questions asked:

Problem name

Difficulty Level

Time to Solve

Pre-requisites

A – Non-Adjacent Flip

Easy

5-6 minutes

Math and basic implementation

B – Mex on Blackboard

Easy

10-12 minutes

Hashing /Multiset

C – Tree and LCS

Medium-Hard

40-45 minutes

Queues

D – Xor Sum 5

Hard

60-65 minutes

Dynamic Programming, Bit Manipulation, and Lucas Theorem

E – Non-Adjacent Matching

Hard

NA

Inclusion-Exclusion Principle

F – Make Same Set

Very Hard

NA

A wide range of topics mainly Dinic’s Algorithm.

Your Experience while solving each question:

A – Non-Adjacent Flip

This question is all about just simple implementation of the conditions given in the question.

  • We are given a string of 0’s and 1’s, and we want to make it alternating (i.e., no two adjacent characters are the same) by swapping adjacent characters. We need to find the minimum number of moves required to do this.
  • If the number of 1’s in the string is odd or there are exactly two adjacent 1’s, it’s impossible to make the string alternating, and we should return -1.
  • If there are no adjacent 1’s in the string, we can make the string alternating by swapping any two adjacent characters. The minimum number of moves required is equal to the number of 1’s divided by 2.
  • If there are exactly two non-adjacent 1’s in the string, we need to check the length and content of the string to determine the minimum number of moves required. If the length is 3, it’s impossible to make the string alternating, and we should return -1. If the length is 4 and the string is “0110”, we need three moves to make the string alternating, and we should return 3. Otherwise, we need two moves to make the string alternating, and we should return 2.
  • Overall, we need to check the number and position of 1’s in the string to determine the minimum number of moves required to make it alternating.

B – Mex on Blackboard

Assume, the mex of the final set is x.

  • In this case, all numbers less than x are in set. The ones, that are not, have to be added. Assume, we added y of such numbers.
  • Now, we have to add k−y more numbers. These are numbers from 0 to x−1
  • We are counting number of sets, so we have to “find number of non-decreasing arrays of length k−y with elements from 0to x−1.
  • Now, not easy combinatorial step: we have to put x−1 stages into k−y+1 positions. This is number of “combinations with repetitions”: CR (k−y+1, x−1)
  • Rewrite as usual combinations: CR(a,b)=C (a+b−1, a)

C – Tree and LCS

For an x, define qx as the number such that pqx=x

  • The minimum similarity has to be at least 1, as one can choose path (x,qx) to make it 1. So, consider constructing a permutation that makes the answer 1.
  • Let’s consider a leaf x. If this node makes a contribution of 1 to the final answer, then the final path must contain path (x,qx) As x is a leaf, x will be the first element in the LCS. Then we only need to ensure that there is no other same element after qx
  • One simple way to do this is to make qx the leaf. Then we get the idea to shuffle the indexes of the leaves. It’s not hard to prove that if we do this, any LCS with a leaf will have length of at most 1.
  • Then return to the original problem. Note that since leaves will not make any further contribution, we can simply delete them and do the same thing on the resulting tree again and again, until there’s only 0/1 nodes left. Then we can do some trivial assignments and the whole process is finished. It can be proved that in this case, the answer is at most 1, which is obviously the best answer we can get.

D – Xor Sum 5

At first, we need to rephrase the problem.

  • For that we need to use the Lucas theorem for which I am attaching a link in this article.
  • https://en.wikipedia.org/wiki/Lucas’s_theorem .
  • Now we need to use dynamic programming in order to solve the remaining problem.
  • Thus, this problem was solved in the last minute.

E – Non-Adjacent Matching

Although I wasn’t able to solve this problem but after the contest, I got it how to solve.

  • Proving Conditions for a Good Sequence:
  • To have a “good” sequence, it needs to meet two conditions. First, the sum of all the numbers in the sequence must be an even number. Second, the sum of any two neighboring numbers in the sequence must be less than or equal to twice the sum of all the numbers in the sequence. These conditions are important because they ensure that the sequence can be used to create a graph with an even number of edges.
  • Using Inclusion-Exclusion Principle:
  • The second condition can be a bit tricky, so we use a method called the inclusion-exclusion principle to make it easier to work with. This condition can only be violated by at most two neighboring numbers in the sequence.
  • To count the total number of valid sequences, we use a mathematical approach called formal power series. This involves finding coefficients of certain functions. We calculate the total number of sequences where the condition can be violated at one fixed position and then multiply it by the length of the sequence. Similarly, we find the sum of the numbers of sequences when the condition is violated at two fixed positions and then multiply it by the length of the sequence.
  • This entire process helps us solve the problem efficiently, and the time complexity is O(M^2 + K + N).

F – Make Same Set

This was the toughest problem I have ever seen in a contest. I needed to see the editorial for reaching to the solution.

  • We want to find a set of numbers that meets certain conditions. To do this, we create a special network with vertices and connections. In this network, we have a source (S) and a sink (T). Each number in our set corresponds to a choice in the network. For each number, we can choose one of three options: A, B, or nothing. We represent these choices with vertices in the network.
  • To find the best set of numbers, we need to flow from the source (S) to the sink (T) in this network. We do this by sending “flow” along paths from S to T. When we send flow along certain paths, some vertices become what we call “no-selection vertices.” These are vertices that don’t have any flow going through them.
  • We use an algorithm called Dinic’s algorithm to find the maximum flow in this network. This algorithm uses the shortest paths, so it won’t create new no-selection vertices. By applying Dinic’s algorithm, we can find a set of numbers that meets the conditions efficiently.
  • This solution allows us to solve the problem in O(N^2) time complexity, which means it’s relatively fast and efficient.
  • But some said in the discussion it could be solved with a time complexity of O(N sqrt(N)).

Conclusion:

I would say overall it was a pretty difficult contest. I was confident about first 3 questions, but the later ones were on a harder side. Moreover, the last question was not been solved even by the top ranker.
Question D was solved by me at the very end of the contest it took me a lot of time to think but it brushed up my Lucas’s theorem concept.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads