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

Автор chromate00, 16 месяцев назад, По-английски
Rating Predictions

The editorial for each task is written by me, chromate00. I tried to explain each task with as much detail I could fit in. Brace yourselves, it is going to be LONG. Please don't try to open all spoilers at once, it lagged my browser. Also, I apologize for not telling you strongly enough to read every problem, almost every tester thought F1 is easy if you read it well...

Also, our fellow wuhudsm told me there will be another community contest in the Gym soon, details will be posted on https://mirror.codeforces.com/blog/entry/138706 shortly :catThink:

UPD: Added solution codes to all solutions.


2063A - Minimal Coprime

Author: chromate00

Hint
Editorial
Code (Python)

2063B - Subsequence Update

Author: Think_Only_Once

Hint
Editorial
Code (Python)

2063C - Remove Exactly Two

Author: chromate00

Hint
Big Hint
Editorial
Code (Python, Approach 1)

2063D - Game With Triangles

Author: wuhudsm (Original Idea) & chromate00 (Modified Idea)

Hint
Big Hint
Editorial
Code (C++)

2063E - Triangle Tree

Author: Think_Only_Once

Hint
Editorial
Code (C++)

2063F1 - Counting Is Not Fun (Easy Version)

Author: chromate00

Hint
Editorial
Code (C++)

2063F2 - Counting Is Not Fun (Hard Version)

Author: chromate00

Hint
Editorial
Code (C++)

UPD: People pointed out that the intended solution in the tutorial is overkill. Yes, I acknowledge this. Please look into the newly added alternative solution if you want a more elegant idea.

Editorial (Alternative)
Code (C++, by Mukundan314)
Разбор задач Codeforces Round 1000 (Div. 2)
  • Проголосовать: нравится
  • +229
  • Проголосовать: не нравится

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

Lightning fast! But I think your problems are not good enough for this historic round.

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

Great blog!

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

    Because many people think Round $$$10^3$$$ should be made of awesome problems as an historic round. Clearly the problems aren't good enough.

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

      Deeply sorry if you thought the tasks weren't awesome, I think we have different thoughts. I think most tasks were great.

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

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

        Well, you promised something epic, that might not be in a "normal div2 round".

        No hate, but imho normal div2 rounds usually have more interesting problems on positions A-D.

        Problem E's intended solution is really nice, but why did noone spot that it can be killed with normal small-to-large? To me E was also "read and immediately know how to solve"

        You managed to make interesting problem F, but intended solution using splay trees is also not in the list of epic things to me :/

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

          I did notice that E can be killed with small-to-large. I thought that the problem still is worth it, but it wasn't a surprise that it is "killed". I was thinking that depth-wise small to large is not a common topic for Div. 2.

          F has A LOT of solutions. Please don't be discouraged, any solution that works is a great solution for it.

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

          Hi, can you describe how are you calculating the answer using Problem's E small to large. I tried to keep an prefix sum array of frequency of depths, or something similar, but I don't know how I would keep it updated in the small to large.

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

            Hi!

            I store arrays of frequency of depths, but with a trick:

            cnt[u][cnt[u].size() — k] = number of vertices in its subtree on the depth (k-1).

            Respectively, when we merge two children, say U and V, we iterate over this array for smaller one, say V is smaller:

            int du = cnt[u].size(), dv = cnt[v].size()
            int tot = /*size of subtree of u*/
            for(int i=1; i<=dv; ++i) {
               tot -= cnt[u][du-i];
               ans += tot*cnt[v][dv-i]*(2*i-1);
            }
            //now do the same with vertices in U on depth <= vertices in V
            tot = /*size of subtree of v*/
            for(int i=1; i<=dv; ++i) {
               ans += tot*cnt[u][du-i]*(2*i-1);
               tot -= cnt[v][dv-i];
            }
            
            • »
              »
              »
              »
              »
              »
              »
              16 месяцев назад, скрыть # ^ |
              Rev. 2  
              Проголосовать: нравится 0 Проголосовать: не нравится

              Could you explain the formula: tot*cnt[v][dv-i]*(2*i-1)? I don't get how we know that we get a nondegenerate triangles from this if we have set only one length

              I realised I was stupid cuz if you have a b sides and we dont know l you have b-a<l<a+b and if you do a+b-b+a+1-2 you get 2*a-1,bruuh

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

              here u have , swapped by comparsion of dp[node].size(), but here dp[node] store information of all vertices at node subtree , on various depths thus , dp[node].size() indirectly gives node subtree depth , so how does time complexity is still NlogN ? By comparison of node subtree size , would have surely mainitned this time complexity

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

              Nice trick, was trying to solve it with small to large, but mine used a Fenwick tree and total complicity was O(n log**2), couldn't find better way to optimize it.

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

        Yeah I wonder why they don't like speed forces for abc and bullshit geometry and greedy+ bullshit implementation for d, and an E which is just standard problem where u added also bullshit geometry to make it Cool but all u did was make a standard problem worse

        Even for a normal div2, this would've been a shitty contest, let alone round 1000

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

          cope

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

          the inclusion of "triangle" doesn't make a problem geometry. D and E has absolutely nothing to do with geometry unless you have not encountered the triangle inequality or area of a triangle formula, which you hopefully would've learned in middle school.

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

            I get ur point, I honestly get it, they aren't geometry problem, they're geometry knowledge is at elementary school level, the point is when u use geometry terms, the problems automatically get shit, I promise if the problem didn't include anything about geometry, mainly using words that are Abt geometry, the problems were probably way more liked and better, also the last div2 b this holds, if the question was find a 4 element tuple with 2 equal elements such that the other two's absolute difference is less than 2*x, the problem would have had a lot more solves a lot faster, by using geometry words and phrases, u just make the problems more annoying, not better

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

        Personally I thought the problems were all great, didn't get all of them but the main idea for CDE required some clever insights and were interesting to me. I also like that F was actually doable for div 2 contestants.

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

        I thoroughly enjoyed the problems. This might be my favorite round ever.

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

I know dogshit about how to solve A i just implemented according to testcases

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

A was easy but B's pretest 2 destroyed me! I was absolutely shocked why it didn't work.

My Approach for B that didn't work
  • »
    »
    16 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +2 Проголосовать: не нравится

    obviously 1 2 2 1 is not going to work when l,r=2,3

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

    Suppose you have the following input

    Input

    Your approach would yield $$$1+1=2$$$, but this is not correct. You can't get to swap both $$$2$$$s with both $$$1$$$s. You wish to swap costly items in $$$a[l:r+1]$$$ with cheaper items.

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

Great set of problems ! Clear description, nice test cases, no mistake ... Kuddos to all organizers. I will enjoy taking more time to solve D and E.

I have been stuck on C, but I don't understand why my submission got WA : 302435615. Could someone give me a hint ?

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

Can anyone help explain how my answer is wrong, I'm just searching for highest degree node, removing it, then finding the highest degree node again: 302462038

edit: I didn’t realize they can give the edges not in order, sorted levels then did same algo and ac

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

I did terrible on this contest

On B, I took 2 subs to realize that I was checking [1,l+1] instead of [1,l].

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

code for problem C

https://mirror.codeforces.com/contest/2063/submission/302448973

can anyone point out why it failed on test 4?

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

Can someone explain why I am getting WA: on my submission 302454358 in problem C. I am doing brute force. I am first greedily picking the first vertice and then removing it after picking second vertice.

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

https://mirror.codeforces.com/contest/2063/submission/302459815

why this is wrong can someone explain ?

i have simply done the process told by the editorial and it is giving wa on 4

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

historical round, cool problems

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

Problem C can be solved using DP without any observation, but the state transition is a little bit complicated.

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

Seems that F2 can be solved much more easily by solving reversely (with a disjoint set union to maintain the father-son relationship)

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

hi everyone! i understand each one of you might've had super high expectations since this was round #1000, i get it, but it's not right to belittle or humiliate other people just because they didn't exactly meet your super high expectations, right? i believe B and C were really nice tasks! also overall the round was enjoyable, the editorial also seems very informative, kudos to the authors + testers for this round. let's not get blinded by our subjective views and insult other people (by downvoting their blogs) who tried their best :) thanks

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

For C I tried getting the maximum degree, adding that to the answer, removing that node and decreasing degree for each neighbour node and then getting the maximum degree again. Why does this fail, any counter case?

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

    there's a slight issue with this. let M be the maximum degree of a vertex present in the tree, and V be the set of all vertices with such degree M. there can be a case where you can remove a vertex from this set and still have another vertex of degree M present, which is the optimal way. however, in your case you aren't considering this and would remove a vertex which would affect the degrees of all remaining vertices in V, and hence, give a sub-optimal answer.

    for example: for a tree of 8 nodes with these edges: -

    1 2 1 3 1 4 2 5 2 6 3 7 3 8

    here you'd end up removing (1, 2) or (1, 3) which would give 4 components, but ideally you should remove (3, 2) and have 5 components.

    hope that helps

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

ThankFully rating can not go below 0.....

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

Could someone give me a hint why my D solution gives WA3

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

There are nothing amazing question in this contest. And just for me , F1 is much more easier than E. Anyway , I'm glad to participate in this 1e3 round. May be it'll be better in 1024 round ? :)

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

[user:chromate00][user:MikeMirzayanov] I have submitted A in the contest. It is showing submitted in the official standings, however it is not showing submitted in the unofficial standings. Kindly rectify the situation. Submission- [submission:https://mirror.codeforces.com/contest/2063/submission/302363475]

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

Editorial seems quite overkill for many of the problems, like binary search for D, and forest of splay trees for F. That being said I also solved F with link-cut tree lmao, though I'm not sure why the editorial doesn't mention that the forest of splay trees kinda just is a link-cut tree?

Anyway, very happy to AK and get rank 27 on such a special round. Screencast here for those who are interested.

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

I don't get why my following logic failed in problem C,

My approach:

Initially ans = 1, and store the number of edges in an array sz.

First, find the vertex with most edges, let's say vertex u with sz[u] edges, then answer increase by sz[u]-1, then decrease sz[x] by 1 for all vertext adjacent to u. Also set sz[u]=0

Then repeat the process to get second vertex v. Then ans again increase by sz[v]-1

Submission:

https://mirror.codeforces.com/contest/2063/submission/302433943

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

    Consider this situation: the tree has five nodes —— 1-2-3-4-5

    Vertex 3 is one of the vertices with most edges, so possibly you tried to remove vertex 3. But the only optimal method is to remove vertex 2 and 4.

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

despite doing horribly i think the problems are slightly better than your avg div 2 , and more balanced , not the quality i expected for the 1000th , still nice tho

edit : i havnt seen problem F , maybe it'll change my view of the contest

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

again messed up B and solved C before B. Also why downvotes, why do you think the problems aren't "awesome" ?

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

F1 was predicted to be easier than D ?! :(

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

302471253 why does this not work for C?

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

I don't know that experts can set most of the questions in a Div2 round before :|

The above is just my opinion, because after a while, I will become an expert :(

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

guys, did nobody solve C using dp/ dfs ?

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

    I have used Eular tour and dp rerooting to find out the answer if I remove the ith node.... and to find this I did something like this. At every node, I am updating the segment tree which stores the count of edges at each node. So as I am removing the ith node I am setting the value to 0 for the ith node and subtracting 1 from my child value and then I am finding the maximum edge of any node using the segment tree.... although this is very overkill for 1500 rated problem this is the solution which comes to my mind so it didn't waste time to think of any case work.

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

Here is my 2 post contest accepted submission for C..

302473806. (using inclusion exclusion property)

302476948 (initial approach with more operations)

can anybody hack these submissions??

During contest I guessed that, checking the first 10 or 20 nodes with higher in degree will do the work.. But I did not implement & I stuck with my initial solution.. Sed,, i missed as always...

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

    Actually, I think it's correct. We can see that the wrong solution fails when there are $$$3$$$ connected vertices with the same largest degree, and we can't pick the middle one as the first to remove. However, when there are $$$4$$$(or more) such vertices, we can pick the first one arbitrarily because it won't affect answer anymore. Therefore, checking 10 nodes(in fact, 3) should be enough.

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

I thought the problems were great, also I appreciate that F was doable even for div 2 participants. I found CDE all very interesting problems, but that's probably because they're at my level.

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

Could anyone explain the 2 pointers approach in problem D please?

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

I had the same direction as editorial for C but couldn't figure it out completely and then had to go back to DP because DP made sense to me quickly but the editorial approach needs some casework to be done.

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

It seems that problems F1 and F2 are very similar to problem E of the recent 997 round.

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

    We noticed this. F1 is similar to that E, but it is quite overkill to apply the same thinking process. Meanwhile, F2 is harder than that E. Therefore, we decided to keep both, for balance and completeness of problemset.

    or well I HOPED F1 will balance things but THEY DIDN'T READ

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

Problem C : extreme brute force solution (302504107)

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

In the editorial of D, shouldn't it be concave instead of convex? Prefix sum of a decreasing sequence should be concave right?

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

    Depends on upwards or downwards. Usually in terms of optimization we call it convex in this situation.

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

      I think in both cases, it should be concave. The definition of a convex sequence says $$$2a_n \leq a_{n-1} + a_{n+1}$$$. Which translates to either $$$a_{n+1}-a_{n} \geq a_{n}-a_{n-1}$$$ or equivalently, $$$a_{n}-a_{n+1} \leq a_{n-1}-a_{n}$$$. This can be understood as follows, for an increasing sequence, the increments are increasing, or for a decreasing sequence, the decrements are decreasing. Intuitively, this also captures the U shape that is commonly associated with convex functions. The function in here, say $$$h(x) = g(x,k-x)$$$, is the opposite of what I described above. Hence I believe its more accurate to call it concave (it also follows the inverted U associated commonly with concave functions).

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

I actually used DP on trees and i don't know why but my solution is failing on Test case 2 C ripped my whole contest. missed D by 5 minutes.

here is my submission if someone would like to help 302414968

P.S.-I personally liked the contest problems

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

F1 is easy. I solved it much earlier than D, the scoring distribution tells enough

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

Overkilled E by narrow-mindedly focussing on a solution with treaps, then saw the editorial lol! Great round tho, befitting of the 1000th round, only wished it were a Div. 1 + 2 :)

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

The official F2 solution using splay tree was way more complicated than what I did so I decided to share it here.

Simple solution to F2 where the most complicated technique being used is max segtree: https://mirror.codeforces.com/contest/2063/submission/302526177

Equivilent quadratic solution: https://mirror.codeforces.com/contest/2063/submission/302525268

Note that

for(int i = l+1; i<r; i++) if(end[i] != -1){
    len[l]-=end[i]-i+1;
    i = end[i];
}

in the quadratic solution is equivilent to

for(int i = l+1; i<r; i++){
    len[l]-=len[i]+2;
}

in the fast solution. I also made len[i] include the start and end parenthesis in the fast solution but not in the slow (since it made it easier to code).

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

OK,but this got TLE and this got AC. I thought it's meaningless to make it TLE since their difference is only the way to save edge.You'd better try some other correct way to do your problem in order to avoid such terrible things.
Sorry for my poor english:(

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

Good contest.

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

Thanks for the round! I'm pretty happy with problem F, I managed to solve it with a normal segment tree and binary searching in it the smallest closing bracket to the left of the query.

Thanks for hosting codeforces 1000th round!!

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

The test cases for C are not comprehensive; my own solution for a fact is wrong. I'll try to explain what I am saying. Say if 3 vertices each have the maximum degree and are connected in a line, and the middle one has many 1 degree neighbours, more than the left and right ones, then we should still remove the left and right vertices

Consider the following test case:

1

22

1 2

3 4

5 6

7 8

9 10

11 12

13 14

15 16

17 2

17 4

17 6

17 8

18 10

18 12

18 14

18 16

17 19

18 19

19 20

19 21

19 22

On this test case, my code gives 8 as the answer, whereas the actual answer is 9. Idk how my code passed all the test cases!

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

Actually, you can transform Problem F2 into a tree, and solve the problem from the back to the front. In that way, it is all about merging components together, which can reduce the time complexity from $$$\mathcal{O}(n\log n)$$$ to something like $$$\mathcal{O}(n\alpha(n))$$$ (the time complexity of a dsu).

The detail that is worth noticing is that if two subtrees with the same parent are both visited, you should merge them too. You can use a virtual node representing the "parent" to solve this case.

Here is the Python implementation (not optimized fully because I wrote it in about 15 minutes): My Submission.

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

In Problem C, this code is according to the solution provided in editorial

Can anyone help understand why this code does not work ?

https://mirror.codeforces.com/contest/2063/submission/302540075 Edit : found it :)

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

second one was really good question.

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

I had a very funny and implementation-heavy solution for problem D. I put x-coordinates of the bottom line in the ordered_set and same for the top line. Then, I did some greedy, I chose min and max point on either bottom or top line (wherever the difference between the coordinates is greater), then I chose a middle point on the opposite side using ordered_set. However, it won't be maximum amount of operations because there can be a case where there will be a lot of points on one side and <2 on another. Therefore, I reverted once last operation and chose points from another side. I don't really know how to prove it, but I got AC by on the first try.

My submission: 302423073

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

Hey everyone, My first comment here :)) I am not getting why my solution for C is incorrect. I am just choosing the nodes with maxdegree and second max degree and checking cases where if maxdegrees are more than 1 and are they connected or not etc. pls help:( my submission: 302456927

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

Can anybody explain me in C question second approach why only trying two vertices of highest degree gave the right answer.

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

Well, F2 can be solved in O( N log MOD ) ( log MOD for calculating inverse mod). I only need to observe the brackets as a tree (assuming that (0, N + 1) is also a good pair)) and then "removing" the brackets (by reversing the queries), which I can maintain by DSU.

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

4th problem "Observe that the value dependent on p is a prefix sum of a strictly decreasing sequence, and thus is convex." can someone please explain above sentence form editorial of 4th question. Suppose we take array containing values 1/i where i being index (talking about 1 based indexing) and we take prefix sum then we do not get convex function. Please tell me where I am going wrong. If someone has done 2 pointer method or binary search then please share your solution.

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

A simpler solution for 2063D — Game With Triangles without binary search, in O(n+m):
At a step with chosen p,q, the next step will be one of ((p+1,q),(p,q+1),(p+2,q-1),(p-1,q+2)). Greedily choose the best next step and assign new value of p,q

https://mirror.codeforces.com/contest/2063/submission/302430925

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

It is really terrible. F1<<E<<D.

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

But obviously there is a offline method can solve F2 in $$$O(n\alpha(n))$$$ with dsu, and u can use this skill to optimize it to $$$O(n)$$$.

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

Can someone explain the following things more clearly in Problem E's editorial?

  1. I didn't understand why the first summation would count the pairs $$$ d_u = d_v $$$ twice? Hence, I also didn't understand its fix.

  2. in the second summation, i didn't understand the logic behind the summation. the above paragraph is very clear which explains the consideration of vertex $$$w$$$ as $$$LCA$$$ but I didn't understand what $$$s_u(S - s_u)$$$ means logically. Hence, the part after it is also unclear.

Explanation would be very appreciated from soneone who knows the answers to these confusions.

Thanks in advance 🧡

  • »
    »
    16 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    1. The pairs $$$(u,v)$$$ where $$$d_u \lt d_v$$$ is only counted once when we check $$$u$$$. However when $$$d_u=d_v$$$, $$$d_u \le d_v$$$ and $$$d_v \le d_u$$$ both hold, and thus $$$(u,v)$$$ and $$$(v,u)$$$ is counted separately while it should not have been.
    2. $$$s_u (S-s_u)$$$, combinatorially, means choosing one vertex from subtree of $$$u$$$, and then choosing another descendant which is NOT in the subtree of $$$u$$$ (thus, the number of cases of the latter is $$$(S-s_u)$$$).
»
16 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I'm confused about this part with Problem D.

Let us define a function $$$g(p,q)$$$ as the maximum score after performing "Operation A" $$$x$$$ times and "Operation B" $$$y$$$ times, assuming it is possible.

Do you mean $$$p$$$ times and $$$q$$$ times? I'm not sure where $$$x$$$ and $$$y$$$ are suddenly coming from.

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

In Problem C, Why it is not optimum to remove the node with maximum number number of edges, then remove the 2nd node with the maximum number of edges after removing the edges from the first operation? like this solution, why it fails? https://mirror.codeforces.com/contest/2063/submission/302950582

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

How are people solving problem E with small to large merging?

I want to get more familiar with that concept but I am not able to come up with the solution from that approach

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

Greedy solution for D if anyone finds above difficult to understand.

https://mirror.codeforces.com/contest/2063/submission/303715832

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
ll n;
        cin >> n;
        vector<pii> a(n + 1, {0, 0});
        vector<vector<int>> edge;
        for (int i = 0; i < n - 1; i++)
        {
            int u, v;
            cin >> u >> v;
            edge.push_back({u, v});
            a[u].s1++;
            a[v].s2++;
        }
        int comp = 0;
        ll maxi = -1, idx = -1;
        for (int i = 0; i <= n; i++)
        {
            maxi = max(maxi, a[i].s1 + a[i].s2);
            if (maxi == a[i].s1 + a[i].s2)
            {
                idx = i;
            }
        }
        if ((a[idx].s1 == 0 && a[idx].s2 == 1) || ((a[idx].s1 == 1 && a[idx].s2 == 0)))
        {
            comp += 0;
        }
        else
            comp += (a[idx].s1 + a[idx].s2);
        
        a[idx].s1 = 0, a[idx].s2 = 0;
        for (auto it : edge)
        {
            if (it[0] == idx)
            {
                a[it[1]].s2--;
            }
            else if (it[1] == idx)
            {
                a[it[0]].s1--;
            }
        }
        
        maxi = -1;
        idx = -1;
        for (int i = 0; i <= n; i++)
        {
            maxi = max(maxi, a[i].s1 + a[i].s2);
            if (maxi == a[i].s1 + a[i].s2)
            {
                idx = i;
            }
        }
        if (a[idx].s1 == 0 && a[idx].s2 == 0)
        {
            comp = max(comp - 1, 0);
        }
        else if ((a[idx].s1 == 0 && a[idx].s2 == 1) || ((a[idx].s1 == 1 && a[idx].s2 == 0)))
        {
            comp += 0;
        }
        else
            comp += (a[idx].s1 + a[idx].s2) - 1;
        cout << comp << endl;    

where it is giving wrong answer?

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

F2 is actually a very standard offline reverse query + DSU trick, took me an incredibly long time to observe...

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

can anyone debug my code I just looked the most 3 degree nodes for all possibilities and if there is a edge between the nodes the answer is the sum of degree sum-2 if there is not the answer is degree sum-1 My submission: https://mirror.codeforces.com/contest/2063/submission/304652149

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

304654404 304653426 304652776

2063C — Remove exactly two

Can someone please explain why any of them gives wrong answer ?

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

Problem C, Solution 2:

Instead of trying 2 max degree nodes, we can choose the node having maximum depth amount all nodes having the max degree count. This is always work as the size of one connected component will be very much larger than other. And it leaves us a choice to choose 2nd node with more degrees.

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

Hii everyone ,trying to solve problem C using DP ,although i have solved it using greedy but just curious.

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

I'm extremely late, but just in case it's helpful to anyone looking at these problems later, I think the alternative solution to F2 in the editorial is also overkill. A few others in the comments have alluded to the solution I wrote, but I'll walk through it in a bit more detail.

Observe that the good pairs have a natural tree structure. Construct one root vertex and n vertices corresponding to each of the good pairs. The parent of each good pair is the innermost good pair in which it is contained, or the root if it isn't contained in any good pair. Intuitively, this tree structure captures the containment relationships between the good pairs. (It might be easier to conceptualize this by imagining adding an extra pair of parentheses enclosing the entire string and assuming this pair is given as the first good pair. Then we can say this pair is the root, and the root is otherwise no longer a special case.)

Define MBSes as in the editorial, except that the good pair enclosing each MBS is included in the MBS. For example, in the bracket sequence (()??), where the question marks are unrevealed parentheses, the MBSes are (??) and (). The key observation is that each good pair that has not been revealed yet is in the same MBS as its parent. (The intuition is that if the parent pair P of the unrevealed good pair X has been revealed, then since P is the innermost good pair containing X, X must be in the MBS contained by P. Otherwise, if P has been revealed, since P is the innermost good pair containing X, the innermost pair containing P must also be the innermost good pair containing X, so X and P are in the same MBS.) Moreover, these connectivity relationships completely define the MBSes, i.e., any pairs that are not forced to be in the same MBS by this property are not in the same MBS.

This is enough to solve the problem offline in $$$O(n \alpha(n)).$$$ Build a DSU where the good pairs are vertices, and iterate over the good pairs in reverse. When we reach a good pair, merge its vertex in the DSU with the vertex of its parent and update the answer accordingly (i.e., if the old components have sizes $$$C_x$$$ and $$$C_y$$$, multiply by $$$\frac{C_{x+y-1}}{C_{x-1} C_{y-1}}$$$).

Obviously, a solution's elegance is subjective, but I think this is a pretty nice solution (and I like this problem a lot more because of this solution than I would have if the only option was to bash with data structures). It's also pretty concise, with less than 40 lines of non-template code. My VC is ongoing, so I can't read other contestants' code, but my guess is that this was more concise than the solutions of other top contestants, allowing me to solve F faster than most other competitors despite taking the time to type F1 separately.

A few other thoughts on the round:

  • A few people pointed out in the comments that E can be solved using small-to-large merging. I don't think this is that bad; the intended solution is not much more difficult to come up with and is very concise. I'd be surprised if small-to-large actually saved a nontrivial amount of time.
  • I wasn't a big fan of D; I found that working out the details took longer than coming up with the general greedy strategy. I felt the same way about C to a lesser extent (I just didn't feel like there was an exciting/subtle idea there), but it didn't bother me much since the implementation was short and it was thus easy to just move on to the next task.
  • I don't think you needed to apologize for not being more clear that contestants should read every problem; the fact that F1 was worth fewer points than D/E should tip off contestants to the fact that it might be easier.
  • F2 was my favorite problem of the round.

Thanks for the contest!

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

In problem D, when I solved the ternary search using the definition of ml = (l * 2 + r) / 3 and mr = (l + r * 2) / 3, the solution got accepted.

But when I used the general definition of ml = l + (l + r) / 3 and mr = r - (l + r) / 3, I got wrong answer verdict on testcase 7. Can anyone explain why?

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

HELP in C!

My Submission — 366425958 I am not able to understand why my code is failing, when i found out 1158th testcase of Test 2 it is,

8 8 5 7 5 2 6 2 1 2 5 1 4 1 3

and the compiler is saying that your output is 4, but while i am testing locally i am getting output as 5.