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

Автор StarSilk, история, 2 дня назад, По-английски

2062A - String

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062B - Clockwork

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062C - Cirno and Operations

Idea: Yakumo_Ran. Solution: Yakumo_Ran. Preparation: Yakumo_Ran, SSerxhs, mejiamejia.

Rate this problem
Solution
Code (C++)
Code (Python)

2062D - Balanced Tree

Idea: StarSilk, SSerxhs. Solution: StarSilk, SSerxhs. Preparation: SSerxhs.

Rate this problem
Solution
Code (C++)
Code (Python)

2062E1 - The Game (Easy Version)

Idea: Yakumo_Ran. Solution: Yakumo_Ran. Preparation: Yakumo_Ran,mejiamejia,SSerxhs.

Rate this problem
Solution
Code (C++)
Code (Python)

2062E2 - The Game (Hard Version)

Idea: SSerxhs. Solution: StarSilk,SSerxhs,PaperCloud,fallleaves01. Preparation: SSerxhs,mejiamejia.

Rate this problem
Solution
Code (C++)

2062F - Traveling Salescat

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062G - Permutation Factory

Idea: StarSilk. Solution: StarSilk. Preparation: StarSilk, SSerxhs.

Rate this problem
Solution
Code (C++)

2062H - Galaxy Generator

Idea: StarSilk. Solution: StarSilk. Preparation: StarSilk.

Rate this problem
Solution
Code (C++)
  • Проголосовать: нравится
  • +82
  • Проголосовать: не нравится

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

In Editorial of C :

Unable to parse markup [type=CF_MATHJAX]

Fixed

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

Unable to view Editorial for problem C

»
2 дня назад, # |
  Проголосовать: нравится +42 Проголосовать: не нравится

We're not beating the speedforces allegations with this one!

»
2 дня назад, # |
  Проголосовать: нравится +58 Проголосовать: не нравится

D>>>>>>>>>>>>>>>>>>>>>E1

»
2 дня назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

nah, no way, I got C wrong cus I forgot to use LL

303138777 and 303120425

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

First time i solved a b AND c in div1+2. Hope to get +ve delta :). thank you!

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

for B should the condition be ti>2max(i−1,n−i)

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

I think for C, one could additionally use the fact that in an array of length $$$n$$$, the sum of differences is $$$a_n - a_1$$$. Thus if $$$a_n < a_1$$$, we reverse else not.

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

In the editorial for B it should be max instead of min

»
2 дня назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится
Rating Prediction
  • »
    »
    2 дня назад, # ^ |
    Rev. 3   Проголосовать: нравится +20 Проголосовать: не нравится

    There should be a row with the average and median. ^_^;

    I like the variance in predictions

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

      I'd like to update it after the actual rating comes out and calculating the errors together

    • »
      »
      »
      2 дня назад, # ^ |
      Rev. 3   Проголосовать: нравится +22 Проголосовать: не нравится

      I like the variance in predictions

      On the contrary, I'm surprised that the variance isn't higher, I personally would have rated H < G < E2 (unfortunately, I spent most of the contest debugging my approach for E2).

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

    C clearly had more than expected solves in the contest. shame on these cheaters.

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

    800 800 800 2400 1600 ? 2700 ? ?

»
2 дня назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

The editorial for C and D is not very clear. What does fa mean in D?

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

not convinced(or did not fully understand) the proof of problem C. please help.

Assuming that in the optimal answer the sequence of operations is 1211121221.

Consider swapping two adjacent operations: 12→21 ... which is equivalent to taking the negation.

so, are we proving that instead of doing 1211121221 we can simply do 1111112222? Then we may need to do negation of all elements based on number of 12 operation swaps?

and of course since 111111 -> no-op we might as well only do 2222?

I think I understand now. However please let me know if I understood something incorrectly. thanks!

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

    No, the argument is that operation 1 simply negates each term of the array, thereby all it does is change the sign of the sum. Thus, it is enough to perform operation 2 and take the absolute value of the sum at each step (Because if the sum was negative then you could have performed operation 1 before and gotten $$$-sum$$$)

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

    Sorry for mixing up 1 and 2. It has been corrected now, and your understanding is correct.

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

      Got it, Thanks!

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

      But why doesn't it matter what the array looked like before you perform operation 1 or 2? The 12 -> 21 negating sum condition only applies to the sum right. But we can get different sums by performing operation 2 on different arrays (different elements at each index). Am I wrong?

      For example, applying 2 to 1212 gives you a different individual elements than applying it to 2121. Wouldn't it?

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

        Think 2121 gives same output as 11

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

        Yeah, I was wondering exactly that, and the editorial lacks so much explanation that you really can't assume that the negative of the array won't generate possibly new (and larger) sums after you apply some other operations on it. That's why I wrote a comment explaining it with proofs of (almost) everything (except trivial things). I think you could like my explanation, so, please, take a look at my comment (somewhere below on this comment section).

»
2 дня назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

I feel like the editorial for B is incomplete, especially for beginners. The most crucial part of the solution is that there never exists a part of the sequence that goes: {i...i+1 ...i... i+1} without visiting both ends of the array which allows one to show that the only optimal sequence is one in which we bounce back and forth from opposite ends of the array.

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

    What does this mean?

    there never exists a part of the sequence that goes: {i...i+1 ...i... i+1} without visiting both ends of the array

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

      Imagine we visited {...2, 3, 2, 3...} at some point in our traversal. This is sub-optimal as the clocks after the first two moves are the same as after the fourth moves, but in the later all other clocks are two less. Hence we should delete the second {2,3};

      This logic can be extended to any subsequence of the form {i, i+1, ...i+k,i+k-1,...i+1, i, i+1, ... i+k} where we can delete the everything after the first i+k and get a strictly better solution.

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

What is meant by "Since 2 does not change the sum of the sequence" in C's editorial? Doing the operation changes the sum right?

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

    Same as above, sorry for mixing up 1 and 2. I have corrected it, but it takes some time to update.

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

dp solution of problem C[Check303116516..]

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

Can anybody explain why this is got WA. I can't understand the editorial for problem C. Here's the submission of c — https://codeforces.net/contest/2062/submission/303119038

»
2 дня назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

B>>>>>>>>>C

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

Quite helpful. Thank you

»
2 дня назад, # |
  Проголосовать: нравится -35 Проголосовать: не нравится

poor contest and even worse editorial

»
2 дня назад, # |
  Проголосовать: нравится +57 Проголосовать: не нравится

The editorial for D is made for people who have successfully solved the problem in the contest. The editorial is not clear at all !

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

    Even I feel so,Can Someone Please provide a more detailed explanation.

    • »
      »
      »
      43 часа назад, # ^ |
        Проголосовать: нравится +26 Проголосовать: не нравится
      • The operation can be rephrased as follows: choose any edge in the tree, consider the two subtrees resulting from removing that edge, choose one of those subtrees, and increment all values in it by 1.

      • Consider any assignment of initial values to the nodes. For any two nodes connected by an edge, if they have different initial values, they can only become equal if we perform the operation selecting the edge between them, and incrementing the subtree of the smaller node.

      • Now, consider what the value of node i will be in the end. We can find this value by rooting the tree at i. The final value after the tree becomes balanced will be val[i] + sum(max(0, val[u] — val[par[u]])). Basically if val[par[u]] < val[u], we will need to increment everything above u.

      • We can prove that actually rooting at any node j != i will yield the same result as i. One way to prove this is by considering what happens to the result when we move from i to a neighbor.

      • Finally, this means we can just root arbitrarily, and greedily minimize sum(max(0, val[u] — val[par[u]])).

      • »
        »
        »
        »
        40 часов назад, # ^ |
          Проголосовать: нравится +8 Проголосовать: не нравится

        I hope there was an option to pin a comment!

        This really helped. Thanks :)

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

    I think it's quite clear for me. Can u explain which part made u confused pls?

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

      Hi, I really don't understand the second part of the editorial. I don't see how we get to the conclusion that au should always be no less than the maximum value of its child nodes av. The proof involves something about decreasing ai and I don't know why do we need to decrease anything?

      • »
        »
        »
        »
        40 часов назад, # ^ |
        Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

        hmm just have a look to the formula ig. let u be the father and v be one of its child,and it's $$$\sum \max(a_v-a_u,0)$$$. let $$$M$$$ be the maximum value of a's among all these $$$v$$$. if we have $$$a_u$$$ smaller than $$$M$$$, just consider what will happen if we "push" the value of $$$a_u$$$ to bigger side(and of course,smaller than $$$r_u$$$). if we set $$$a_u\rightarrow a_u+1$$$, the value of $$$\sum \max(a_v-a_u,0)$$$ will decrease at least one, while the value of $$$\max(a_u-a_{fa},0)$$$ will increase at most one. thus it's not worse than the previous $$$a_u$$$. so it's always optimal to set $$$a_u$$$ bigger when $$$a_u\le M$$$, which lead to the observasion in the editorial.

      • »
        »
        »
        »
        36 часов назад, # ^ |
        Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

        "decrease" means comparing taking the maximum with maximum -1

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

      Thanks, but it's okay now. One of my friends already explained it to me.

»
2 дня назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

Please don't use symbols that are hard to understand in editorials like in E1 for example: w,dfn,nfd,pre,suf,low

I am really trying to understand the solution, but I can't really fathom it due to them.

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

    Yes. I can't identify/understand which algorithm is being used in the solutions for E1, and the variable names are far from helpful.

    • »
      »
      »
      39 часов назад, # ^ |
        Проголосовать: нравится +4 Проголосовать: не нравится

      low is definitely not a good name as a variable since it collides with the low in tarjan algorithm. maybe using end or ed will be better?

      • »
        »
        »
        »
        35 часов назад, # ^ |
          Проголосовать: нравится +10 Проголосовать: не нравится

        For people learning tarjan algorithm, they often come up with low because it has similar operations (max the dfn).

        dfn stands for dfs number, which is the order of the DFS process in the algorithm. e.g., dfn[root] = 1.

        low stands for the maximun dfn in the subtree. e.g., low[root] = n.

        I use low as the variable name too and I just come up with the name myself. Is this a coincidence?

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

    Not sure why you're being downvoted. I thought the same thing.

  • »
    »
    44 часа назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    I am also not able to make sense of techniques used to find greater elements in subtree from the code, but now the editorial has been updated and it explains what they are doing.

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

Can someone explain why this code fails:

https://codeforces.net/contest/2062/submission/303155437

»
2 дня назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Can someone tell me why it doesn't get TLE? I literally brute-forced the operations and memoized the array itself. Submission Thanks

  • »
    »
    47 часов назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    All the second operation does is multiply the array by -1 after the next operation of the first type, this means applying the second operation twice undoes itself no matter how many operations of type one are performed inbetween. Hence you only have 2*N states.

»
2 дня назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

I somehow misread the problem B and thought we need to spend an additional second if we want to reset the clock. Does anyone know if this version of the problem is solvable?

  • »
    »
    47 часов назад, # ^ |
      Проголосовать: нравится -8 Проголосовать: не нравится

    I'm pretty sure the strategy of simply walking back and forth still is optimal, so you can solve the problem by updating the length of the walk as you have to reset an additional clock each cycle.

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

      It doesn't really work, e.g. in test like 10 100 100 100 100 you can just restart "big" clocks one by one between restarting the small one and the answer would be YES, whereas your strategy fails.

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

Below I explain the solution to exercise C, doing exactly what the editorial didn't do.

Let's call the reverse instruction as '1' and the difference instruction as '2'. Let's create a new instruction, the "negative" instruction, that I will call from here on as '3'. That instruction multiplies each element of the input array by -1.

Theorem 1) Applying operation 1 two consecutive times is the same as not doing anything (proof omitted)

Theorem 2) Applying operation 3 two consecutive times is the same as not doing anything (proof omitted)

Theorem 3) Applying operation 1 does not change the sum of the input array (proof omitted)

Theorem 4) Applying operations "12" to a sequence is the same as applying operations "231".

Proof:

Let the input array be [a1, a2, a3, ..., an]. Applying "12" on it leads to:

After 1: [an, a(n-1), a(n-2), ..., a1]

After 2: [a(n-1)-an, a(n-2)-a(n-1), ..., a1-a2]

Applying "231" to [a1, a2, a3, ..., an]:

After 2: [a2-a1, a3-a2, ..., an-a(n-1)]

After 3: [a1-a2, a2-a3, ..., a(n-1)-an]

After 1: [a(n-1)-an, a(n-2)-a(n-1), ..., a1-a2]

So, the sequences of operations "12" and "231" are equivalent.

Theorem 5) Applying operations "23" to a sequence is the same as applying operations "32".

Proof:

Let the input array be [a1, a2, a3, ... an]. Applying "23" on it leads to:

After 2) [a2-a1, a3-a2, ..., an-a(n-1)]

After 3) [a1-a2, a2-a3, ..., a(n-1)-an]

And applying "32" to [a1, a2, a3, ... an]:

After 3) [-a1, -a2, -a3, ..., -an]

After 2) [a1-a2, a3-a2, ..., a(n-1)-an]

So, the sequences of operations "23" and "32" are equivalent.

===================

With those theorems in hand, let's solve the exercise.

Let s be any sequence of operations that leads to the maximum possible sum. For example, s may look something like this:

s = 11112221212212112111

According to Theorem 1, I can remove every pair of consecutive 1's, which would give me the following sequence:

s = 222121221221

According to Theorem 3, I can remove the last 1 of the sequence:

s = 22212122122

Now, from the left to the right of the sequence, let's change any appearance of "12" to "231". That won't change the final sum because Theorem 4 says those instructions are equivalent. If, while changing "12" to "231", we end up with consecutive 1's, we simply remove them (because of Theorem 1). If we end up with a 1 on the end, we simply remove it (because of Theorem 3). Below I simulate that process:

s = 22212122122

s = 222231122122 (Theorem 4)

s = 2222322122 (Theorem 1)

s = 22223222312 (Theorem 4)

s = 222232223231 (Theorem 4)

s = 22223222323 (Theorem 3)

As you can see, we ended up with a sequence made only of 2's and 3's. Now, let's apply Theorem 5 several times and move all the 3's to the end:

s = 22222222333

And now let's remove consecutive pairs of 3's, because Theorem 2 allows us to:

s = 222222223

This simulation gives us a general idea of what any optimal sum sequence looks like: it is either:

  • An empty sequence (s = "")

  • A sequence of 1 or more 2's followed by none or only one 3 (s = "222...2223", s = "22...2", etc)

Now, our algorithm should simply try all of those sequences and grab the one with the highest sum, as shown here: (303162845)

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

is there any solution for E2 using small to big and segment tree

this is my attempt for this problem. if anyone can explain why my code gives me wa or gives a corner case for my code thanks.

https://codeforces.net/contest/2062/submission/303162086

»
45 часов назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

Sadly i was not aware that if we resubmit a accepted qestion then the time of resubmition will be considered for that problem and my rank droped by 4000.

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

Can anyone recommend me some resources to solve E1? I got the idea in the contest but the editorial isn't clear about how to achieve the idea. Looking at others solutions, I feel like there's a gap in my knowledge somewhere on the topic.

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

I didn’t solve D just because I didn’t consider the tree with only one point, which resulted in me doing nothing for the last hour. That's funny.

»
44 часа назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Thanks for the excellent contest. Problems D,E and F are all intersting!

»
43 часа назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

How is the construction of array $$$a$$$ in Problem D’s editorial optimal?

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

problem C, the case 9 9 7 9 -9 9 -8 7 -8 9 why the answer is 2056?

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

Can someone who have solved E1 tell how they solved it and came to the conclusion their method was right?

  • »
    »
    33 часа назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    At first we need to sort all node by their weight, then our strategy is choosing second biggest node (when it sorted by weight), and checking if in its subtree contains all bigger weight node or not, if not we will choose it, next player will choose the biggest, so there will be no other option, so we win. If it contains all, just check next smaller weights, until we find answer. If we dont find it, then there no answer. I solved that intuitively, that's why I wasn't sure if its correct or not :)

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

Problem D: Anyone getting Runtime Error in Test 8? Please help me how my solution got accepted in 7 test cases but runtime error in test 8?

https://codeforces.net/contest/2062/submission/303196494

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

How does the C++ solution of D work?
Why does this line erase(e[v], u); not TLE?
Should it not be $$$O(n^2)$$$?

  • »
    »
    38 часов назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    The total time these erase operations take throughout the whole DFS is $$$\mathcal{O}(E)$$$, because this operation is done for each vertex only once and for each vertex it takes time proportional to the number of edges attached to it. Since this is a tree, it's also $$$\mathcal{O}(V)$$$.

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

Is there any proof for B ?

»
38 часов назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

why O(n^2) gives TLE in E1, even when time limit is 4 sec ?


const int N=1e6+5; vector<int> tree[N]; int down[N]; int up[N]; int id; bool visited[N]; int p[N]; void dfs(int u) { if(visited[u])return; down[u]=++id; visited[u]=1; p[id]=u; for(auto it:tree[u]) { dfs(it); } up[u]=++id; } bool comp(pair<int,int>&a,pair<int,int>&b) { return a.first>b.first; } void solve() { int n; cin>>n; for (int i=1; i<=n; i++) { tree[i].clear(); id=0; visited[i]=0; } vector<int>wt(n+1,0); for(int i=1;i<=n;i++) { cin>>wt[i]; } for(int i=0;i<n-1;i++) { int x,y; cin>>x>>y; tree[x].push_back(y); tree[y].push_back(x); } dfs(1); vector<pair<int,int>>ans; for(int i=1;i<=n;i++) { int l=down[i]; int r=up[i]; for(int j=1;j<=id;j++) { if(j>=l && j<=r)continue; if(p[j]<=n && wt[p[j]]>wt[i]){ ans.push_back({wt[i],i}); } } } for(int i=0;i<=3*n;i++) { p[i]=0; } if(ans.size()==0) { cout<<0<<endl; return; } sort(ans.begin(),ans.end(),comp); cout<<ans[0].second<<endl; }
»
37 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is the reason why the first comparison in question C did not take an absolute value compared to the prefix sum without operation?

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

2062B Clockwise ans in c++ is wrong my code is also similar except var name . testcase 1 both code passed but testcase 2 failed both.

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

This had such an uneducative C, the previous round's B was better than this round's C. Just simple observation that sum of differences is an-a1,solves this.

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

Anyone have material For understanding E1 problem i see sol but that is beyond my understanding since some are using eulertour or something can someone provide problem resource for this pls

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

E1 editorial says "Additionally, we can enumerate the nodes in descending order of wi and maintain their lowest common ancestor (LCA). If the LCA of all v satisfying wv>wu is not a descendant of u, then there must exist a node v outside the subtree of u that satisfies wv>wu."

what if there are n/2 nodes with maximum w[v] and we need to check each one of them with every other w[u] to find the answer and exactly the last one we check is the answer?

isn't it O(n^2lg)? or even O(n^2)?

can someone explain if I'm wrong?

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

Don't know if anyone can't understand the implementation of E2 from official editorial but here is my own code, based totally on what the editorial said, using LCA and basic data structures. maybe it's easier to understand?

»
33 часа назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

You can also use Small To Large for problem E1.

Idea : - If the current value don't contain the previous larger values then the node containing it is definitely winnable. Or if it does contain, if the previous larger values do exist outside of the subtree of this node then it is also a winnable node.

This is my code :

https://codeforces.net/contest/2062/submission/303225889

»
29 часов назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Does anyone have proof for why solution for D actually works?

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

    imho, I don't see myself looking at D and thinking ohh well this should work. (maybe my skill issue).

    Apart from that I wanted to say that I loved problem F.

  • »
    »
    13 часов назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    I will explain how i approached the problem:

    Lets root the tree at node $$$1$$$. We need to find the minimum value $$$V_u$$$ for the subtree of some node $$$u$$$. (we can always increase the value later if we need)

    Assume the subtree of all of the children of $$$u$$$ have an equal value $$$V_i$$$. we have two cases:

    • $$$V_i \leq R_u$$$, we can just increase that subtree till $$$L_u \leq V_i$$$

    • $$$V_i > R_u$$$, we need to increase all of the tree except that subtree, the final answer increases by the difference $$$V_i - R_u$$$ and $$$V_i$$$ "decreases" till its at most $$$R_u$$$ (the only thing that changes is their relative difference)

    The minimum value of the node $$$u$$$ is the maximum value among $$$V_i$$$ and the minimum value of a leaf is just $$$L_u$$$.

    Code

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

      The thing that is bugging me is why choosing any root for this operation is fine?

      • »
        »
        »
        »
        13 часов назад, # ^ |
          Проголосовать: нравится +5 Проголосовать: не нравится

        Consider an operation: root the tree at node $$$u$$$ and increase the subtree of node $$$v$$$ ($$$u \neq v$$$). we can always move the root $$$u$$$ towards $$$v$$$ as long as $$$u \neq v$$$ and the operation will have the same effect.

        So the operations can be simplified to two adjacent nodes (an edge) or equal nodes (which just increases the entire tree).

        That means if we root at any node $$$u$$$, the operation can be done on some edge and increase either the entire tree, the entire tree except a subtree or only the subtree. so we can just consider one root.

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

Hello, pls someone help me to find mistake in my solution of D: My idea is that I am taking a leaf and its parent and trying to make them equal in minimal amount of steps, then just deleting leaf, cause it will behave like its parent

my submission

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

the editorialist must explain in the D, why taking any node as root for the greedy strategy yields in same answer.

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

Bottom up pull DP for C -> Click

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

The DP of F is fun, but I have a question. How do you approach the required transformation of the max? Are these transformations common? I don't think I can come up with one even if I think about it for a week. I wonder how the rankers came up with it.