Open In App

Contest Experiences | Codeforce Round: #871 (Div. 4)

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

About the contest:

The contest was organized by Codeforces on May 6, 2023. It consisted of 8 questions and the time given to solve them was 2 hours 30 minutes i.e. 150 mins.

Link of the Contest: Codeforces Round #871 (Div 4)

Overview of the Questions

Problem Name

Difficulty

Pre-Requisite

Time to Solve by Me

Number of Attempts

Love Story

Easy (800)

Implementation, Strings

2 mins

1

Blank Space

Easy (800)

Implementation

5 mins

1

Mr. Perfectly Fine

Easy (800)

Implementation, Greedy

9 mins

1

Gold Rush

Easy (1000)

brute force, dfs and similar, dp

17 mins

2

The Lakes

Medium (1100)

graphs, dsu, dfs and similar

32 mins

1

Forever Winter

Medium (1300)

dfs and similar, graphs, math

48 mins

3

Hits Different

Hard (1600)

data structures, math, dp

47+ mins

Don’t Blame Me

Hard (1700)

bitmasks, combinatorics, dp, math

EXPERIENCE:

Problem A: Love Story

My Experience: Like usual Div 4 contests, the first 2-3 questions are pure implementation based. This was a cakewalk problem which could be easily solved even by beginners in a few minutes.

Accepted Solution:

Simply follow the instructions given in problem. Initialize a string temp = “codeforces” and simply count the number of indexes where s[i] != temp[i]. The time complexity of the code will be O(N).

Problem B: Blank Space

My Experience: This question was also implementation based. One had to simply follow the instructions as mentioned in the problem statement and the question could be solved within 5 mins.

Accepted Solution:

The Approach to the question was very easy. Simply count the number of consecutive 0’s in the array. The segment with maximum number of consecutive 0’s will be the answer. The time complexity for each test case will be O(N).

Problem C: Mr. Perfectly fine

My Experience: This was a greedy question which required simple conditional statements. Initially I tried to use extra space, but during the coding part, I realized it could even be solved without using extra space by just using 3 variables and it got accepted.

Accepted Solution:

The approach was to find the minimum time to collect each of “11”, “10” and “01” strings. Let minimum time to collect “11” be a, “10” be b and “01” be c. Both skills could be gathered either through “11” or combination of “01” and “10”. Hence, the answer will be simply min(a, b + c). In case the answer comes out to be INT_MAX, we will return -1. The time complexity for each test case will be O(N).

Problem D: Gold Rush

My Experience: This was a pure mathematics related problem. I tried to understand the test cases but it didn’t helped that much. Later, I created my own test cases and found out the pattern that how can we divide a number into 2 numbers such that one is double of another. From this pattern I got the approach for using recursion in this problem. Although I missed an edge case that the number should be divisible by 3, therefore I got a WA.

Accepted Solution:

If you divide a number into 2 numbers such that one number is the double of other (like 6 => 2 + 4), then one number will be 1/3rd of the original number and the other number will be 2/3rd of the original number. (1/3rd of 6 => 2 & 2/3rd of 6 => 4). This forms the recurrence relation that if using either of the relation, we can reach the number ‘m’ then we return “YES” else we return “NO”. The base case will be if n < m or n % 3 != 0, then simply return false. The time complexity for each test case will be O(n log32).

Problem E: The Lakes

My Experience: Being honest, I expected a gradual increase in the difficulty for of problem from D to E, but against my expectation, the problem E was a standard island problem in graph theory using BFS/DFS. I had solved similar type of problems on other practice websites before so I started coding instantly just after looking at the first test case. I was delighted that it got accepted in the first try itself.

Accepted Solution:

My approach to this problem was using DFS. I ran a loop for every cell of the matrix and every time I find a non zero number (lake body), I perform DFS for that volume. Make sure to mark the cells of the lake visited so that it may not get added in the areas of any other lake volumes. The edge cases were simply boundary conditions where the index must be within the boundaries of matrix and the cell must be a Non zero cell. We simultaneously keep track of the maximum volume of lake encountered so far. At the end we simply return the maximum volume. The time complexity to solve this question was O(mn).

Problem F: Forever Winter

My Experience: As soon as I read the description of the problem I realized that it was yet another graph problem because nodes and vertices were mentioned along with graph like figure. however, I saw that pattern of graph problem for the first time. The question was straight forward, but the challenging part was to identify an approach to solve it. I tried to recall all the concepts about graph theory and identify which one could be used to solve this problem. Since it required counting the number of connections of each node, I tried to approach it using indegree and outdegree array concept but it gave WA. However, making my own test cases for the problem helped a lot to analyze the relation between x and y in snowflake graph.

Accepted Solution:

It is very obvious that the central node/vertex of the snowflake will have the most number of connections among all the nodes in the entire graph. We need to find the degree of each vertex and store it in a degree vector. After this, we make a hashmap which will store the count of each degree of non-leaf nodes in the graph. Let the number of branches in the snowflake from central vertex be 5 and number of branches from individual non-leaf non-central vertex be 3, then the map will look like this: {3 : 5, 5 : 1} (because there are 5 nodes with 3 branches and 1 central node with 5 branches). Hence, using this map we can simply declare 5 as X (because there is only 1 central node in the graph and the central node will always have maximum branches). Now, Y could be easily figured out using the relation map[degree_count] >= 2. This is because all the leaf nodes will have degree 1 and central vertex’s map value is also 1. Hence, the value of Y will be equal to the degree_count. The time complexity of this solution for each test case will be O(n + m).

Problem G: Hits Different

My Experience: Being honest, my adrenaline was at peak when problem F got accepted. Although I knew, I had got several penalties and took more time for F problem. The first moment I read problem G, I thought it would be an advanced math problem. Although after the contest ended, I got to know that it was a DP problem which was supposed to be solved using precomputation. The problem statement was very short, but it was challenging to identify what approach to use in it. I thought to find a relation between sum of individual layers in the pyramid. However, the constraints to this problem were 10^6 which meant that it was supposed to be solved in O(n) time complexity. I struggled with the problem for the rest of the duration of the contest. At the end, I was unable to find an approach for the problem.

Conclusion

Like usual Div 4 contests, the first 3-4 problems were pure implementation based which didn’t required use of any data structure and algorithm concept. The problems G and H were very challenging and difficult. Overall it was a great contest for me, I ended up solving 6/8 problems. This contest was not focused on just one or two concepts of DSA, but rather it had several varieties of problems covered like Math, Graph, DP, DSU, Sorting, Combinatorics, Bitmasking, etc. The learnings from from this contest was that one must solve different patterns of problems from every topic and not just standard problems. Also, one cannot blindly assume the problems to come from regular topics, they may come from rare topics like combinatorics, dsu, segment tree, trie, etc.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads