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

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

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!
Разбор задач Codeforces Round 1044 (Div. 2)
  • Проголосовать: нравится
  • +240
  • Проголосовать: не нравится

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

thanks for fast editorial

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

Nice round with nice problems!

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

Beautiful interactive!

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

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

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

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

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

    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.

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

    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.

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

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?

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

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!

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

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

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

    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.

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

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.

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

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

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

      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?

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

        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.

        • »
          »
          »
          »
          »
          15 месяцев назад, скрыть # ^ |
          ← Rev. 2  
          Проголосовать: нравится +4 Проголосовать: не нравится

          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.

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

            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?

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

              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.

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

GG! Fast editorial!

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Fast editorial!

»
15 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -8 Проголосовать: не нравится

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

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

    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?

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

      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.

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

fast editorial before GTA-6

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

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.

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

    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.

  • »
    »
    15 месяцев назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

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

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

fast editorial :0

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

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

»
15 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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)

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +19 Проголосовать: не нравится

CHICKEN JOCKEY!!

»
15 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +16 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +15 Проголосовать: не нравится

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

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

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

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

    DP is easier to follow.

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

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

      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.

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

    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

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

      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.

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

Nice round!

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

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

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

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

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

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?

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

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

»
15 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

    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
»
15 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Problem D was awesome

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

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

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.

  • »
    »
    15 месяцев назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    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.

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

excellent contest:)

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

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

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

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.

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

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.

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

Nice problem F

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

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.

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
← Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
15 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

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

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

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.

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

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

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

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

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

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

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

    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
»
14 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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.

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

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

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

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.