Contest Experiences | Codeforces Round: #851 (Div. 2)
Last Updated :
30 Oct, 2023
ABOUT THE CONTEST:
- In this Contest, there are a total of 6 problems, and 2 hours and 15 minutes time given to you to solve this problem.
- For each wrong submission, there was a 10-minute extra penalty.
Link of the Contest: https://codeforces.com/contest/1788
My Experience:
I was able to solve all the problems of these contests.
OVERVIEW OF ALL CONTEST PROBLEM:
Easy
|
5
|
1
|
Easy
|
10
|
1
|
Easy-Medium
|
15-20
|
1
|
Medium
|
15-20
|
2
|
Hard
|
20-25
|
2
|
Hard
|
20-25
|
2
|
LET’S DISCUSS THE QUESTIONS:
Problem A – One and Two
To solve this problem we first iterate through the array from left to right and calculating the product of elements up to the current position. Then compare the products from steps 1 and 2 to find a position ‘k’ where they are equal. Output the value of ‘k’ as the smallest possible k. If no such ‘k’ exists then is output -1.
Problem B. Sum of Two Numbers
To solve this problem, we can use a straightforward approach. The key idea is to split the given integer n into two non-negative integers x and y such that the sum of the digits in x and the sum of the digits in y differ by at most 1. First we start with x as the largest possible number with a sum of digits of ‘n’ or ‘n – 1’ and ‘y’ as 1. Then keep reducing ‘x’ by 1 and increasing ‘y’ by 1 while ensuring that the sum of digits in ‘x’ and ‘y’ doesn’t differ by more than 1. At the end output the values of ‘x’ and ‘y’ as the solution.
Problem C. Matching Numbers
to solving this problem we first check if n is a power of 2. If it’s not, then print No because a valid pairing is not possible. If n is a power of 2, it is always possible. Create pairs starting from the smallest and largest numbers and pair them such that the sums of paired numbers are consecutive and distinct. Output “Yes” to indicate a valid pairing is possible, and then print the pairs.
Problem D. Moving Dots
To solve this problem, we can first sort the array of initial coordinates x in ascending order. For each pair of dots, calculate the number of distinct coordinates where they stop moving. To calculate the number of distinct coordinates for a pair of dots, consider the coordinates between the two dots. We can calculate the difference between the coordinates of the two dots and add one to it. This gives the number of distinct coordinates where they stop. Sum up these results for all possible pairs. Output the sum modulo 10^9 + 7.
Problem E. Sum Over Zero
In this problem to find the maximum sum of lengths of non-overlapping segments such that each segment’s sum is greater than or equal to zero. First iterate through the array while keeping track of the current sum. Whenever the current sum becomes negative, reset it to zero, indicating the start of a new segment. Update the maximum sum found so far. The maximum sum represents the answer.
Problem F. XOR, Tree, and Queries
To solve this problem, construct a tree from the given edges and then use depth-first search to calculate the XOR values for the edges on each path from a chosen root vertex. For each query, determine if there’s a valid assignment of edge weights that satisfies the XOR condition. If a valid solution exists, output yes along with the edge weights such that a1,a2,…,an−1 is minimized. If no solution exists, output “No.”
Conclusion:
At the end I was able to solve all problem. For me last problem F was difficult, I require more time to solve this last questions.
All the best for upcoming contest.
Share your thoughts in the comments
Please Login to comment...