srishtik_16's blog

By srishtik_16, history, 23 months ago, In English

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.

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
23 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there an easy way to solve the second problem? I do not have the screenshot, so describing the problem here:

Spoiler

Also, can someone share the 6th problem and the approach?

  • »
    »
    23 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    How many did you solve?

    • »
      »
      »
      23 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.

  • »
    »
    23 months ago, # ^ |
      Vote: I like it +20 Vote: I do not like it

    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$$$.

    • »
      »
      »
      23 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.

      • »
        »
        »
        »
        23 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I took a global 5000*5000 array and it passed.

    • »
      »
      »
      23 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Nice solution, thanks.

»
23 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    23 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      23 months ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Apply the Dijkstra algorithm from each node.

      Code
»
23 months ago, # |
  Vote: I like it +4 Vote: I do not like it

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.

»
23 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone explain the problem statement for C?

  • »
    »
    23 months ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    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).

    • »
      »
      »
      23 months ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      I got partial marks in this problem. Could not see exact marks as test finished :|

      O(n^3 * log(n^2) Approach
      • »
        »
        »
        »
        23 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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].

»
23 months ago, # |
  Vote: I like it 0 Vote: I do not like it

this contest is a lil bit harder than the previous one! ig

  • »
    »
    23 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    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.

»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How much problems we need to solve to get shortlisted for interviews?

  • »
    »
    22 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    There is no such criteria, it depends on the recruiter to set the bar.