CodeAgon 2023 by Trilogy Innovations was held today. We can use this blog to discuss the problems and their approaches. I personally solved 2.5 problems, 1st , 4th and 5th partial (300 points). Would be interested in knowing the solutions for the others.
My Approaches:
Problem 1: Sort the array and find median. Try changing 1st two elements, last 2 elements, and 1st and last elements to the median, and try to find the optimal answer out of these 3 cases.
Problem 4: Solved it with DP,where DP[i] = expected steps for number i, Transistion -> dp[i] = (sum of (dp[div] + 1) for all divisors of i except 1) / count of divisors of i. The required answer is sum of dp[i] for all 1 to n, divided by n.
Problem 5: Did it partially with approach similar to this Problem.
Would love to hear your approaches too.
Thanks.
Is there an easy way to solve the second problem? I do not have the screenshot, so describing the problem here:
Given an array A of size N and an integer B, you need to find the minimum value of sum of abs(A[i] — A[i + B]) for all i from 1 to N — B, over all permutation of A. Constraints : N <= 3e5 and B <= min(n, 5000).
Also, can someone share the 6th problem and the approach?
How many did you solve?
I was able to solve 4 fully, wasted much time on that expected value problem becoz of my dumb mind that ignored a very important line to read. I feel like 2nd problem is solvable, but 6th is way out of my reach.
1)For a particular sequence of $$$I, I+B, I+2B...$$$ It is optimal to put the elements in sorted order so that the sum of differences is equal to max-min.
2)If we separate the sequences {$$$0, B, 2B...$$$}, {$$$1, B+1, 2B+1...$$$}, once we start giving elements to one sequence it is optimal to first fill the all the indices of this sequence (assuming we fill in sorted order), before we start filling another one.
3)So the final answer would be equal to max-min-(the differences b/w consecutive elements where one sequence ends and other one begins)
4)We can subtract exactly B-1 differences but once we take one the next one can be only after we complete taking an entire sequence.
5)There are exactly $$$(N \bmod B)$$$ sequences with size $$$\lceil \frac{N}{B}\rceil$$$ and the remaining sequences have size $$$\lfloor \frac{N}{B}\rfloor$$$. Just apply $$$B^2$$$ dp where $$$dp[x][y]$$$ is the state where you have taken x sequences of size $$$\lfloor \frac{N}{B}\rfloor$$$ and y with size $$$\lceil \frac{N}{B}\rceil$$$.
Were you able to pass this solution with a 2-d dp array? I had to solve it iteratively filling the array diagonally as with recursive implementation I got MLE.
I took a global 5000*5000 array and it passed.
Nice solution, thanks.
I solved two problems, two operations and a treasure hunt completely. I just need to know the logic of the intersection of segments. I came up with the idea of a disjoint set union but I'm not able to implement it correctly.
What was your approach for treasure hunt? Thought of doing it with djikstra but couldn't give it much time due to wasting time on 2 and 5. 5th looked really easy initially and then kept getting harder.
Apply the Dijkstra algorithm from each node.
I solved 5 full and partial in a direct Dijkstra problem C (166/300). Most probably there was an overflow issue due to the usage of int, I noticed it at the end, but could not correct it till the end :(
Really disappointed after missing one of the easiest problems.
Can someone post the images of the problems? I will share my approach.
Problems
What was your time complexity?
Not sure :(
Can you share your approach for 5th problem (Intersection of segments).
Shared Here: https://codeforces.net/blog/entry/111126?#comment-990209
What was your approach for the 6th problem?
https://codeforces.net/blog/entry/111126?#comment-990209
How did you check that you got 166/300 points. hackerbhaiya
At the bottom it was written Partially Correct : 166/300
Did it come as Correct Answer even after passing only 166/300 tests?
It came as Partially Correct: 166/300
Also, there were some lines above it mentioning something about inefficiency and overflow issues.
Hey I also had the same partial score on problem c. I had a logical error in my code. I was not considering the cases when we go using one path and come back using another.
Oh F!!! I thought that the problem was to comeback using the same path (basically 2 times the path used to reach destination ) :(
Can anyone explain the problem statement for C?
For each vertex u, we want to find minimum cost to get a treasure located at some vertex v. Cost to get treasure is, A[v] + (edge weights while going to v) + (edge weights while returning to u) + (number of edge while returning to u) * weight of treasure).
I got partial marks in this problem. Could not see exact marks as test finished :|
Main thing to observe was we may not follow the same path while returning. We want to minimise (path weight + number of edges in path * B[v]) while returning. For each u, we will calculate 2 dp values.
dp1: dp1[v] = minimum weight to get to v from u.
dp2: dp2[v][cnt] = minimum weight to get to v from u using cnt edges.
dp1 can be calculated using Dijkstras.
For dp2 also I was using Dijkstras which resulted in O(n^2 * log(n^2)) complexity and thus TLE.
Now using dp1 and dp2 we can calculate for each u the minimum cost to get the treasure in O(n^2). So overall complexity will be O(n^3)
For dp2 we don't really require the cnt part.The minimum price to reach v from u can be found by running dijsktra on a graph where each edge weight=edge weight+B[v].
Were you able to get AC on this?
Yes.
this contest is a lil bit harder than the previous one! ig
I found it easier. Last year the problem involved topics like small to large merging on tree,lazy segment tree,staircase nim and one tough bitmask optimization.
are you talking about December 22?
How much problems we need to solve to get shortlisted for interviews?
There is no such criteria, it depends on the recruiter to set the bar.
Do you get any mail for next process?