Contest Experiences | Codeforce Round: #879 (Div. 2)
ABOUT THE CONTEST: Codeforce Round: #879 (Div. 2):
- This contest was conducted by codeforces #879 for Div 2 Participants.
- In this Contest, there are a total of 6 problems, and 2 hours and 15 minutes are given to solve this problem.
- The penalty for each wrong submission was 10 minutes.
Link of the Contest: https://codeforces.com/contest/1834
My Experience:
I was able to solve 4 out of 6 problems during these contests.
OVERVIEW OF ALL CONTEST PROBLEM:
Problem Name |
Difficulty |
Approx time to solve |
Number of submissions by me |
---|---|---|---|
Unit Array |
Easy |
8 – 10 minutes |
1 |
Maximum Strength |
Easy |
10 – 15 minutes |
1 |
Game with Reversing |
Easy-Medium |
10 – 15 minutes |
2 |
Survey in Class |
Medium |
20 – 25 minutes |
2 |
MEX of LCM |
Medium-Hard |
– |
– |
Typewriter |
Medium-Hard |
– |
– |
LET’S DISCUSS THE QUESTIONS:
Problem A: Unit Array
Approach: In this question, we reads an array of integers, count the occurrences of two specific values (1 and non-1), and then calculate and prints results based on these counts. First, read the size of the array and initialize counters for occurrences of 1s and non-1s. Then for each element in the array, update the counters based on the element’s value. Determine which counter is larger (1s or non-1s). If 1s are more or equal, check if the count of non-1s is even. If it is even, print 0, esle if odd, print 1. If non-1s are more, calculate the difference between non-1s and 1s, distribute the difference equally, and print a result based on whether the adjusted non-1 count is even or odd.
Time Complexity: O(t * n)
Space Complexity: O(N)
Problem B: Maximum Strength
Approach: In this question ,we need to calculate the number of digits that differ between two integers, a and b ,and then ccomputethe sum of these differing digits. To solve this we first read the number of test cases. For each test case, read two integers, a and b. Then calculate the number of digits in b by finding the length of its string representation and subtracting 1. This determines the number of iterations needed to compare digits from left to right. Use a while loop to compare the leftmost digits of a and b, If they are equal, then move on to the next digit by dividing both a and b by 10^d. Continue this process until we find the first differing digit or until n reaches 0. Calculate the difference in the number of differing digits and print the result. The formula used to solve this question is : * n + (b//(10n)) – (a//(10n)), which sums up the differing digits.
Time Complexity: O(N)
Space Complexity: O(1)
Problem C: Game with Reversing
Approach: In this question, we need to compare two strings a and b of equal length n. It calculates the minimum number of operations needed to make the two strings identical by counting the differences in characters. To solve this first read the length of the strings n and the strings a and b. Check if a and b are already identical, if yes then print “0” (no operations required) and move to the next test case. Initialize two counters x and y to keep track of differences when comparing a and b. Iterate through the characters in a and b using a loop. For x compare characters at the same position in a and b, if they are different then increment x. For y compare characters at mirrored positions in a and b, if they are different, increment y. At the end calculate the minimum number of operations needed to make a and b identical using these formulas min(2*x – (x&1), max(2, 2*y + (y&1) – 1)).
Time Complexity: O(N), N is the length of the strings.
Space Complexity: O(N)
Problem D: Survey in Class
Approach: A problem is to find the maximum possible result by selecting three special ranges from a list of n ranges and applying a specific function f to each combination. To solve this For each test case, Input the number of ranges n and m (not used in the code). Read n pairs of integers representing n ranges into the l list. Identify three special ranges: p, q, and r. Initialize and to store the maximum result. Iterate through each range and calculate f for three different combinations. Update ans with the maximum result among these combinations. At the end print ans multiplied by 2 as the final result for the test case.
Time Complexity: O(N)
Space Complexity: O(N)
Problem E: MEX of LCM
Approach: This question aims to find the smallest positive integer that is not achievable by taking the least common multiple (LCM) of elements from a given set. First read the number of test cases t. Then for each test case: Read an integer n representing the size of the set. Initialize two sets s and v. s stores LCM values, and v stores the unique values from the input. Iterate through each element of the set: For each element ‘a’, create a temporary set ‘ss’ and add a to it. For each element x in the s set, calculate the LCM of ‘a’ and ‘x,’ and add it to ‘ss’ if it’s less than or equal to 1e6. Update the ‘s’ set with the values from ‘ss’. Update the ‘v’ set with ‘a’ and all the new LCM values. Initialize ‘mex’ to 1. While ‘mex’ is found in the ‘v’ set, increment ‘mex’. Last print the ‘mex’ value as the result for the test case.
Time Complexity: O(t * n)
Space Complexity: O(1e6)
Problem F: Typewriter
Approach: To solve processes a sequence of operations on an array and answers queries efficiently. First, read the length of the array ‘n’ and the array elements. Then precompute values to optimize query processing.For each query: If it is of type 1 or 2, then update the position ‘p’ based on the query. If it’s of type 3, toggle between two sets of precomputed values. Output the result based on the updated position ‘p’ and the current set of precomputed values.
Time Complexity: O(N)
Space Complexity: O(N)
Conclusion:
At the end I was able to solve A , B ,C, and ,D problem. For me problem E and F was difficult. All the best for upcoming contest.
Contact Us