sammyuri's blog

By sammyuri, 12 months ago, In English

Thank you for participating in my round! I hope you all enjoyed it.

Rate the contest!

2133A - Redstone?

Hint 1
Solution
Code (C++)
Code (Python)
Rate the problem!

2133B - Villagers

Hint 1
Solution
Code (C++)
Code (Python)
Rate the problem!

2133C - The Nether

Hint 1
Hint 2
Solution
Code (Python)
Rate the problem!
Bonus

2133D - Chicken Jockey

Hint 1
Hint 2
Hint 3
Solution
Code (Python)
Rate the problem!

2133E - I Yearned For The Mines

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Code (C++)
Rate the problem!
Bonus (easy)
Bonus (hard)

2133F - Flint and Steel

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem!
  • Vote: I like it
  • +240
  • Vote: I do not like it

| Write comment?
»
12 months ago, hide # |
 
Vote: I like it +25 Vote: I do not like it

thanks for fast editorial

»
12 months ago, hide # |
 
Vote: I like it +22 Vote: I do not like it

Nice round with nice problems!

»
12 months ago, hide # |
 
Vote: I like it +22 Vote: I do not like it

Beautiful interactive!

»
12 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

Can anybody tell me how to develop the intuition for problems like D?

  • »
    »
    12 months ago, hide # ^ |
     
    Vote: I like it +33 Vote: I do not like it

    Just brute force the sample cases until intuition magically comes to you.

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

    Short answer is "solve more problems". I know this is not what you're looking for but it is what it is.

    To solve problem D, you need to make some observations -- for example, realizing that having more than 2 stacks is unnecessary. The fun part of competitive programming is making such observations. It's a skill that isn't easy to improve, but you can get better by learning from problems: by reflecting on the ones you couldn't solve, analyzing how you might have solved them.

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

    You can try swapping two consecutive operations. If they are not adjacent, then obviously the later operation is done first. Then, connect the elements to be deleted with those adjacent to the later operation. The operation times will be: {t[0], t[0] + 1, ...}, {t[1], t[1] + 1, ...}, ..., {t[k], t[k] + 1, ...}

    where $$$t[0] \gt t[1] \gt \dots \gt t[k]$$$.

    For each segment, the gain is calculated as follows: let the first position of the segment be $$$i$$$. If the segment length is 1, it cannot decrease; otherwise, for the second element, it can decrease by $$$\min(i, a[i+1])$$$, and all other elements decrease by 1. This way, a DP can be designed.

    In other words, swapping adjacent operations often determines the structure of the operation order.

    It is translated by CHAT GPT, forget my poor English.

»
12 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

This was the first time I came across C-type of question. I have not yet seen the answer. Any tips for attempting before viewing the answer?

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

    Try a lot of what ifs.

    Like what would happen if I picked half the vertices, or all the vertices or one vertex or two vertex, with different starting points.

»
12 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

I felt so good after solving C! The approach is so simple! Just do:

  • Query each node with all nodes allowed -> get the longest path length from each.

  • Pick the node with the maximum length as start.

  • From there, repeatedly try to move to any next node that has the longest path = current longest path — 1

  • Follow until the path ends!

»
12 months ago, hide # |
 
Vote: I like it +22 Vote: I do not like it

I want to say D explanation leaves some room of ambiguity, especially the fall mechanism.

»
12 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

Ok, my D solution was really weird. The main idea was going top to bottom, but that made the dp harder and lost me a lot of time

  • »
    »
    12 months ago, hide # ^ |
     
    Vote: I like it +7 Vote: I do not like it

    Same, i'v noticed that, falling that happened above i, doesn't affect any fall damage for mobs below. Because of this, i thought i can do something greedy, and decided that DP idea it's wrong.

»
12 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

In problem C's solution, if we use binary search to find the first node whose query returned $$$k-1$$$, which is connected to the node whose query returned $$$k$$$, we may use less time to find the answer.

  • »
    »
    12 months ago, hide # ^ |
     
    Vote: I like it +14 Vote: I do not like it

    That was the solution to the original version of the problem, but it was found to be too hard, so we nerfed it to allow $$$2n$$$ queries. (The statement does comment that Steve is particularly generous with the query limit!)

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

      Don't we need additional queries to check which k-1 nodes is connected to which k node and how binary search will help here?

      What will be the maximum query limit required to solve this problem?

      • »
        »
        »
        »
        12 months ago, hide # ^ |
         
        Vote: I like it +11 Vote: I do not like it

        If there is only one $$$k-1$$$-node, you don't even need a query. Otherwise the worst case for binary search is when there are $$$3$$$ nodes in each layer, requiring $$$2$$$ queries. (In fact you don't really need binary search, you can just check groups of $$$2$$$ until you have at most $$$2$$$ nodes left, but binary search might be easier to implement.)

        One tester mentioned it might be possible in better than $$$\frac{5}{3}n$$$ queries as well, although it sounds quite hard.

        • »
          »
          »
          »
          »
          12 months ago, hide # ^ |
          Rev. 2  
          Vote: I like it +4 Vote: I do not like it

          We could use this binary search, but for groups of size 3 and 5 we randomize which elements to query(just random shuffle and query first half). This way we get expected number of queries to be $$$\frac{14}{9}n$$$.
          Edit: For this to work you have to query the smaller half.

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

            What problem binary search is solving here? Are we using binary search for deciding which node to take among all k-1th level nodes after taking one from kth level node? If so then how will we decide which half to discard?

            • »
              »
              »
              »
              »
              »
              »
              12 months ago, hide # ^ |
               
              Vote: I like it +4 Vote: I do not like it

              As is Sving1024's solution we query first half of elements. If the result is 1 than we know that the node we are looking for is not in this half, so it must be in the other, else it is in this half. The only change is that if on the given level there are 3 or 5 nodes we random shuffle them before we binary search and query the smaller half.

»
12 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

GG! Fast editorial!

»
12 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Fast editorial!

»
12 months ago, hide # |
Rev. 2  
Vote: I like it -8 Vote: I do not like it

I don't know if someone looked in that way, but I think D was almost identical to A very famous problem on leetcode, House Robber

Explanation :-

We want to maximize the fall damage, so we need to find a sequence of attacks that does that.

-> Kill mob[i — 1] which makes mob[i] take (i — 1) damage,

-> Kill mob[i] which makes **mob[i + 1**] take i damage

We cannot benefit from both of these operations because the stack breaks, this is why it becomes similar to HOUSE ROBBER, i.e we cannot kill adjacent mob and want to maximize the fall damage

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

    Just because a problem's solution uses a similar thought process does not make it "almost identical". This comment is like saying that every greedy problem is "almost identical" to any tutorial lesson on greedy algorithms. What's the point?

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

      No, you are absolutely right, but the intution behind it’s solution is same, because the idea is similar. There can be many ways to solve it, but this is one of the way someone can look at. I was just saying that.

      Like for example CSES has a problem named Coin pile, that solution also works for another problem, “A knight initially at top left cell(0,0) of an infinite chess board and can only go down or right (as a knight goes in L), can it reach cell (a,b). Surprisingly if you think carefully its similar to coin pile problem.

      I am talking about the institutions of solving a problem, after doing a few problems, sometimes we can just link it with some other problems. I know same or similar code doesnt mean same or similar question but institution can be similar or linked atleast.

»
12 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

fast editorial before GTA-6

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

In problem D, Is it possible to enum the $$$i$$$ from $$$n$$$ to $$$1$$$ when DP? Because if $$$i \leq j$$$, kill the j-th mob will better than kill the i-th first.

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

    Probably hard to iterate from n to 1?

    At j, it is easy to calculate the cost to let j take non-1 fall damage. But it is hard to calculate the cost to let j take 1 fall damage which depends on all i that is smaller than j.

  • »
    »
    12 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Yes it can be done from top to bottom as well, but it becomes little messy

    My Code
»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

fast editorial :0

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

I really like the "Bonus(hard):Implement the checker." of the problem E. It is indeed quite interesting.

»
12 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

sammyuri my identical submission(https://codeforces.me/contest/2133/submission/335385249) failed in system testing but it passes post contest(https://codeforces.me/contest/2133/submission/335402623)

»
12 months ago, hide # |
 
Vote: I like it +19 Vote: I do not like it

CHICKEN JOCKEY!!

»
12 months ago, hide # |
Rev. 2  
Vote: I like it +16 Vote: I do not like it

C Bonus solution:

Let $$$p_u$$$ be the longest path starting at node $$$u$$$. If our solution path contains node $$$u$$$, any neighbor $$$v$$$ such that $$$p_v = p_u - 1$$$ can be the next in our solution path. The editorial looks for $$$v$$$ by linearly searching all nodes that satisfy this condition. This takes 1 query per possible neighbor and $$$n + n-1 = 2n-1$$$ queries total.

Instead, we can reduce the queries by using a smarter search. let $$$C$$$ be a set of all canidate nodes $$$v$$$ such that $$$p_v = p_u - 1$$$. Think about what happens if we query the longest path starting at $$$u$$$ using a subset $$$T \subseteq C$$$. If the longest path is 1, that means that all $$$v_i \in T$$$ are not neighbors of $$$u$$$, so we can disregard all of them. If the longest path is >1, that means that some $$$v_i \in T$$$ is a neighbor of u, and we can reduce our search to only nodes in $$$T$$$

We can "binary search" $$$C$$$ by breaking it in half into 2 subsets, $$$T_l \cup T_r = C$$$. If the result of querying $$$T_l$$$ is 1, we know we can reduce our search to only nodes in $$$T_r$$$ and vice versa. If both $$$T_l$$$ and $$$T_r$$$ return a path longer than 1, a valid path continuation exists in both sets and we can search either. It is impossible for both $$$T_l$$$ and $$$T_r$$$ to result in a path length 1. Therefore, we only need to query $$$T_l$$$ to get this information.

This solution will take $$$\sum_{i=1}^{k-1} \lceil \log_2 p_i \rceil$$$ queries. Because $$$\lceil \log_2 a \rceil \le \tfrac{2}{3} a$$$ for integers (equality at $$$a=3$$$), this solution takes $$$n + \frac{2}{3}n = \frac{5}{3}n$$$ total queries. The worst case can be achieved with a graph that looks like 1 path of length $$$k$$$ and 2 paths of length $$$k-1$$$

Solution Code: 335388268

»
12 months ago, hide # |
Rev. 2  
Vote: I like it +15 Vote: I do not like it

It's a bit of a pain to implement and way less elegant than the editorial solution, but DP also works for E with the following state (note: when I say "good" subtree below I'm referring to a subtree that has had nodes deleted such that the remaining nodes are disjoint paths):

$$$dp[v][0]$$$ — minimum operations to make v's subtree good assuming v's parent edge exists and v is not deleted

$$$dp[v][1]$$$ — minimum operations to make v's subtree good assuming v's parent edge does not exist and v is not deleted

$$$dp[v][2]$$$ — minimum operations to make v's subtree good assuming v is deleted

The key insight for this is that a forest that is a collection of disjoint paths is equivalent to a forest where all the nodes have degree $$$\leq 2$$$

335402889

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

    Yes! You are right! I use the same way to solve E. Although I solved it after compitation. :)

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

    DP is easier to follow.

    I don't fully understand the intuition and the correctness of the coloring approach in the editorial.

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

      I found the following more intuitive:

      Our goal is to mark at most floor(n/4) nodes to be deleted such that the remaining forest will be made of chains.

      Base case — there is < 4 nodes. We're done, this graph must be a chain.

      Inductive step — Pick one of the deepest leaves of the tree. Let's move one node up and focus on it's parent, p. If p is already marked for deletion, remove the subtree rooted at p and continue induction on the remaining subtree.

      Otherwise, there are 3 possibilities:

      1. p has >= 3 children
      • Mark p as deleted, remove the subtree rooted at p, then continue induction on the remaining tree
      1. p has 2 children
      • Mark the parent of p as deleted (2 up from the deepest node), remove the subtree rooted at p, continue induction on remaining tree
      1. p has 1 child
      • Remove the deepest leaf, continue induction on the remaining tree

      For every node marked as deleted, at least 3 nodes are "saved" (not marked for deletion). Therefore, we will perform op 1 on at most floor(n/4) nodes.

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

    I also tried to use DP to solve this problem during the competition, but my code was too complicated, so I couldn't finish it during the competition. I think your code is very concise, but the output part of my code is very complicated. (I'm going to cry.)

    My Code

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

      Yeah reconstructing optimal decisions from DP is always kind of annoying, but I've generally found this pattern to be useful where I create an $$$opt$$$ array that has the same dimensions as my DP array and stores the optimal decision for each DP state — then you just recurse downward from the final DP state to reconstruct your solution.

»
12 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Nice round!

»
12 months ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

Honestly, this was the best round I have ever participated in! Thank you so much for the round!

»
12 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

i'm sorry, but the tutorial needs another tutorial to be understandable :)

»
12 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Great Problems! Came back to cf after a while and loved solving these !!

»
12 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

WTF is this solution for problem A ? Am I dumb, or can we just have a O(n) solution by using a frequency table ?

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

    You can do that, although it would be $$$\mathcal{O}(n + A)$$$ where $$$A = \text{max}(a[i])$$$, so it wouldn't work if the constraints on $$$a[i]$$$ were higher. (But given the low constraints it's fine.)

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

    using map is still $$$O(n \log{n})$$$

    using unordered_map is $$$O(n)$$$ worst case which might cause $$$O(n^2)$$$

    • »
      »
      »
      12 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      They are most likely referring to creating a frequency table using an array of fixed length (i.e. 99, 100, or 101 depending on implementation).

    • »
      »
      »
      12 months ago, hide # ^ |
       
      Vote: I like it +8 Vote: I do not like it

      unordered_map is unnecessary. unordered_set is enough and using unordered_set can't cause TLE (335440738). I think it's impossible to create a hack when $$$2 \leq a_i \leq 100$$$ because the hacks rely on hash collisions, and the possible inputs in this range can't produce many collisions (maybe even none?).

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

    Yeah that's what I did since there were small size constraints. Maybe the editorial was trying to be more general?

»
12 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

In hint 2 of problem D, it says

hint 2

I think it should say

hint 2

Otherwise, when read alongside with hint 1, it sounds like a mob can ...

talking about hints
»
12 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Missed problem E because of a one-line bug. Maybe next time...

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

I have a solution for D, it is a bit simple similar to "Mortal Combat" Problem the DP 1500 problem on codeforces, but in reverse. The solution basically was caring about four cases HH, HR, RH, RR and saving the best H and the best R for every i

where H represents the best score if I damaged i directly, and R represents the score if I damaged the one before i and i was just a bottom of a new stack, HH means i hit and i + 1 hit and the rest are similar things, the hardest part for me was the RR part, because we will not take R from i + 1 safely but instead of letting its prev be i it will be 1, have a look :)

def solve():
  n = int(input())
  a = list(map(int, input().split()))
  
  dp = [[-1, -1] for _ in range(n)]
  dp[-1] = [a[-1], max(0, a[-1] - (n - 1))]
  for i in range(n - 2, -1, -1):
    # HH
    hh = a[i] + dp[i + 1][0]
    # HR
    hr = a[i] + dp[i + 1][1]
  
    dp[i][0] = min(hh, hr)
    
    # RH
    rh = dp[i + 1][0] + max(0, a[i] - i)
    
    # RR
    val_up = a[i + 1] - (i + 1)
    rr = max(0, a[i] - i) + dp[i + 1][1] + (val_up + ((i + 1) - 1))
    
    dp[i][1] = min(rh, rr)
    
    
  print(max(0, min(dp[0])))
»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I am quite curious about how the checker for E works.

What I have in mind is that for every 1 operation, it checks whether the current component is a linear path and whether it started from one of the tails, moving node by node to the other tail.

or am i missing something?

  • »
    »
    12 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    That's kind of the idea, but you need to keep track of potentially multiple components where Herobrine cannot be and there are some special cases that could make the checker run in $$$\mathcal{O}(n^2)$$$ if not handled properly as well. And it's not just linear paths; for example, if you had a "star" tree (one central node connected to $$$n-1$$$ others), you can also catch Herobrine using only operation $$$1$$$. (It takes more than $$$n$$$ operations, but you have to still account for this because it could be a subtree of a much larger tree that "donates" some extra operations, and a particularly weird solution might do it this way.)

»
12 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I was stuck in the problem D, i thought approaching from the suffix was the best solution, however the tutorial says otherwise. Still, I really liked it — thanks to the authors <3

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

    I wrote the following believing that the two approaches have some difference, but now I see nothing. Just posting this anyway.

    Solution using dp on suffix
»
12 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Problem D was awesome

Edit: Also, does anyone have a greedy solution for D?

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

This was my first contest and I was only able to solve Problem A. I hope to do better in future contests Any tips on how to spot hidden details and build intuition For example, Problem B turned out to be solvable but during the contest I could not figure out the right approach.

  • »
    »
    12 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    The best way to get better at spotting hidden details is to 1) thoroughly read a problem (especially when starting out) while trying to think about why they included said info, and most importantly 2) practice/experience. Most of it comes from solving a lot of problems and naturally building an intuition.

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

excellent contest:)

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

There are many thought-provoking questions in this round.I like it.

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

In problem E, I have made out that I need to split the tree into paths. But how can we find a way to split as the amazing answer shows? Coloring the tree just seems an impossible wild imagination for me.

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

I hope the writer can improve the description later.

I didn't realize the D's description is wrong until 0:30......

I think the race can't appear such important problem.

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

Nice problem F

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

Perhaps we can find the answer to Problem E using the minimum number of operations.

Use the DP method on the tree to find the minimum number of nodes to be deleted so that the remaining portion of the tree after deleting the node consists of exactly a certain number of chains. Then remove these nodes, traverse each chain in order once, and perform operation 1.

»
12 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

F is hard.problem D and E is good.This is very thought-provoking content.

»
12 months ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

A really stupid solution to problem D but i like it cause of the optimization from n^2 to n

so dp[i]= min attacks to clear i...n

now to calculate dp[i] in n time we can check for every j>i.

something like

1] h[i]+dp[i+1]

2] h[i]+h[i+1]-(i+1)+dp[i+2]

3] loop j over i+2->n and find the minimum of sum till j +dp[j+1] call this above; so dp[i]= h[i]+h[i+1]-(i+1)+ above

                ll above=1e18;
		ll so=0;
		for(int j=i+2;j<n;j++){
			so+=a[j];
			so--;
		 	above=min(above,so+dp[j+1]);
		}

but then it can be noticed that the value of above can only change at the current i if it does change so a simple check a[i+1]+dp[i+2]-1 will do this you can try to prove this greedily .

here: 335464375

»
12 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Dang, fast editorial!

Why didn't my solution pass for D though:

https://codeforces.me/contest/2133/submission/335390561

I really wish C wasn't interactive but whatever

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

Is there any O(n^2) solution's code or equation of Problem F? I'm a bit confused about that.

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

I would say that the $$$O(n^3)$$$ limit for C is quite confusing, as this problem is easily solved in $$$O(n^2)$$$ time.

  • »
    »
    12 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +5 Vote: I do not like it

    The interactor runs in $$$\mathcal{O}(n^3)$$$, as each query can take $$$\mathcal{O}(n^2)$$$ time to answer.

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

Can someone tell me In E why can we just split the tree into components of size 4 or less

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

In D.. the chicken jockey problem.. I am 100% sure my approach is correct.. I know that if a mob is to be killed its better to be killed while its in the original stack.. also.. its not beneficial to kill 2 consecutive mobs.. so what i do is i calculate the answer for an approach where i only kill the bottom-most mob in the og stack.. let the next one take 1 fall damage.. then do it till the whole stack is dead.. next i calculate for each index how much benefit i'll get if i kill that mob.. i only care if this value is negative.. coz im gonna add this to my ans... now i traverse from the right side to the left and for every continuous negative subarray i figure out which non continuous subsequence gives the minimum sum and add this to my og ans.. this however fails on the 3rd test case by 2 points.. Any help is much appreciated... (hands praying emoji)

heres my submission for reference 335568823

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

Can the E problem be solved using the degree of the graph? Perform the 2 operation on all degrees greater than 2, then only single nodes, double nodes, and chains remain, and then proceed with the examination

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

    That can use up to $$$\frac{4}{3}n$$$ queries, which is too many. Here's a small case for which it doesn't work: the only solution is to perform operation $$$2$$$ on node $$$4$$$, which has degree $$$2$$$.

    Spoiler
»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Someone please explain me B. Villagers ? even chatgpt can't explain it to me, I fail to understand how pairing from the last -> start after sorting them will get the most optimal emrald cost ?

  • »
    »
    12 months ago, hide # ^ |
    Rev. 4  
    Vote: I like it 0 Vote: I do not like it

    You can check that for any villager pair $$$(i, j)$$$, after applying:

    $$$v[i] := v[i] - \min(v[i], v[j])$$$
    $$$v[j] := v[j] - \min(v[i], v[j])$$$

    it's guaranteed that at least one of the values becomes $$$0$$$.

    Because of this, pairing $$$\left\lfloor \frac{n}{2} \right\rfloor + (n \bmod 2)$$$ times is enough to connect all villagers, since for any pair $$$(i, j)$$$ where $$$v[i] = v[j] = 0$$$, the connection cost is $$$0$$$.

    Now, if we're trying to minimize $$$\max(v[i], v[j])$$$, notice that:

    for any $$$v[i] \leq v[j] \leq v[k]$$$, pairing $$$(i, k)$$$ leads to a larger or equal cost than pairing $$$(i, j)$$$.

    Based on this, a greedy strategy would be:

    • Sort the input array.
    • Pair adjacent elements.

    Handling Even and Odd $$$n$$$:

    If $$$n$$$ is even, the algorithm is straightforward: just pair all adjacent elements.

    If $$$n$$$ is odd, there are two natural ways to handle the unpaired element:

    Option 1:
    Pair $$$(v[1], v[2]), (v[3], v[4]), \ldots, (v[n-2], v[n-1])$$$, then leave $$$v[n]$$$ as is.
    Total cost:
    $$$\sum_{i=1,\, \text{step } 2}^{n-2} \max(v[i], v[i+1]) + v[n]$$$

    Option 2:
    Leave $$$v[1]$$$ unpaired, and pair the rest: $$$(v[2], v[3]), (v[4], v[5]), \ldots, (v[n-1], v[n])$$$.
    Total cost:
    $$$v[1] + \sum_{i=2,\, \text{step } 2}^{n-1} \max(v[i], v[i+1])$$$

    You can compute both and take the minimum, this will give you an AC.

    But if you want to push even further, you'll notice that Option 2 is always better. Reason:

    • Option 1 includes $$$v[2] + v[4] + \ldots + v[n]$$$
    • Option 2 includes $$$v[1] + v[3] + \ldots + v[n]$$$

    Since $$$v[1] \leq v[2], v[3] \leq v[4], \ldots$$$ it can be proofed the second sum is smaller.

    My explanation isn't fully rigorous, but I hope it helps.

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

gear ratio was a very good question, learnt something new

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

is it possible solve F in O(n)? I got someidea but stuck at O(n log log n) by veb tree yet. wanna know if there's improve

»
11 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

For D, I think it would be nice to assert the fact that the top mob always takes fall damage in the optimal answer when $$$n \geq 2$$$. The dp relation makes more sense with this assertion.

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

F actually is far more easier than I thought,but it is hard for me still,the dp part is hard-thinking

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

Isn't it possible to solve problem E with this simple algorithm?

  1. Do DFS from any vertex.

  2. Consider the vertices in the exit time order.

  3. If the current vertex is connected to 3 or more undeleted vertices in its subtree, delete it.

Now for every deleted vertex there will be at least 3 undeleted, meaning that we delete at most n/4 vertices. At the same time each component consists of at most 3 vertices, meaning that each vertex has degree <= 2, meaning that every component is a bamboo.