Open In App

Codeforce Round: #875 (Div. 1 + Div. 2)

Last Updated : 05 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

ABOUT THE CONTEST:

  • This Contest was organized by Codeforces on 28 May 2023 for Div 1 Participants.
  • In this Contest, there are 6 problems and 2 hours to solve this problem.
  • The penalty for each wrong submission was 10 minutes extra time.

Link of the Contest: https://codeforces.com/contest/1830

My Experience:

I was able to solve 5 problems out of 6 problems during these contests.

OVERVIEW OF ALL CONTEST PROBLEM:

Problem Name

Difficulty

Approx time to solve

Number of submissions by me

A. Copil Copac Draws Trees

Easy-Medium

5-10

1

B. The BOSS Can Count Pairs

Easy-Medium

10-15

1

C. Hyperregular Bracket Strings

Easy-Medium

10-15

1

D. Mex Tree

Medium-Hard

20-25

2

E. Bully Sort

Medium-Hard

20-25

3

LET’S DISCUSS THE QUESTIONS:

A. Copil Copac Draws Trees

To solve this first read the number of test cases t. For each test case: Read the number of vertices n. Read the edges of the tree. Initialize a variable readings to 0. Create a data structure to represent the tree. Implement Copil Copac’s algorithm: Start with the first vertex. Iterate through the edges in order. For each edge, if it connects an already drawn vertex to an undrawn vertex, mark the undrawn vertex as drawn and increment the readings count. Repeat this process until all vertices are drawn. Output the number of readings for each test case.

B. The BOSS Can Count Pairs

To solve this first Iterate through the arrays with nested loops to generate all pairs of indices i and j. Check if the condition ai * aj = bi + bj holds for each pair. Increment a counter whenever the condition is satisfied. At the end return the count as the number of good pairs for each test case.

C. Hyperregular Bracket Strings

To solve this problem, we can utilize the concept of dynamic programming. Consider creating a DP array to count the number of ways to form valid bracket sequences of length n. Then, for each interval [li, ri], subtract the count of valid bracket sequences within this interval. Finally we compute the total count of valid bracket sequences.

D. Mex Tree

To solve we perform a depth-first search to traverse the tree. While traversing, keep track of the count of distinct colors reachable from each node by considering its ancestors. The maximum possible value of any coloring of the tree is the sum of these counts of distinct colors for all nodes, excluding the root.

E. Bully Sort

We can use a segment tree to maintain the count of ‘bully swaps’ needed for a given segment of the permutation. Simulate the sorting process by tracking the largest and smallest elements not in their correct positions to determine the number of swaps required. Perform the updates and adjust the segment tree to reflect these changes. After each update, query the segment tree to obtain the number of swaps required.

Conclusion:

At the end I was able to solve 5 problem out of 6 problem. For me last problem was difficult. All the best for upcoming contest.
Thank You !!!


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads