Блог пользователя srishtik_16

Автор srishtik_16, история, 23 месяца назад, По-английски

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.

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    How many did you solve?

    • »
      »
      »
      23 месяца назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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 месяца назад, # ^ |
      Проголосовать: нравится +20 Проголосовать: не нравится

    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 месяца назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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 месяца назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Nice solution, thanks.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 месяца назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      Apply the Dijkstra algorithm from each node.

      Code
»
23 месяца назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain the problem statement for C?

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    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 месяца назад, # ^ |
        Проголосовать: нравится +6 Проголосовать: не нравится

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

      O(n^3 * log(n^2) Approach
      • »
        »
        »
        »
        23 месяца назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    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.

»
23 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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