atcoder_official's blog

By atcoder_official, history, 2 years ago, In English

We will hold AtCoder Beginner Contest 351.

We are looking forward to your participation!

  • Vote: I like it
  • +52
  • Vote: I do not like it

| Write comment?
»
2 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

why are the scoring distribution not uniform in ABC's? just a question. By uniform I meant that they vary from contest to contest.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

GLHF!

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I wish I could AC the first five questions.

»
2 years ago, hide # |
Rev. 3  
Vote: I like it -7 Vote: I do not like it

Problem C was sh*t

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

is there any possibility to solve F using Dynamic segment tree ??

»
2 years ago, hide # |
 
Vote: I like it +34 Vote: I do not like it

I might be the unluckiest man ever to get 6 second places in all ABCs while never getting the first place :( Why are these Japanese so fast :cry:

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

getting WA on 16 testcases for problem D, any clue what edge cases i am missing,

https://atcoder.jp/contests/abc351/submissions/52879952

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

    I guess this is the issue: fields next to magnets can (and sometimes should) be visited multiple times from different directions, so you have to either not mark them as visited, or clean them up after every traversal.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Well. ABC began to have Grid BFS again! I only remember that ABC stopped doing so several months ago. I'm bored with the similar BFS problems. The codes are long and difficult to debug.

»
2 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Since no Editorial is available until now, it will be helpful if somebody can share their approach in $$$E$$$.

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

    I. Since the moves preserve the parity of x+y, I first split all points into two independent groups and add their results together at the end.

    II. For every group, the distance then is simply distance in 'maximum' metric ($$$max(|x_0-x_1|,|y_0-y_1|)$$$) (easy to see).

    III. To calculate the sum of distances, I first transform this metric from maximum into Manhattan, for which the solution is simple and quite well known:

    Spoiler

    IV. Finally, we need to calculate sum of differences over both coordinates, which can be done separately by sorting and maintaining sum and count of previously added elements.

    V. The final distance has to be divided by 2, which is an artifact of the transformation from point III but also easy to see when running against samples.

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

      As I understand, what you are saying means that, if we have $$$2$$$ points: ($$$x_1$$$, $$$y_1$$$) and ($$$x_2$$$, $$$y_2$$$)

      After transformation, they will be: ($$$x_1+y_1$$$, $$$x_1-y_1$$$) and ($$$x_2+y_2, x_2-y_2)$$$

      Where the Manhatten distance between the transformed points is equal to the actual distance between the original points:

      |$$$x_1+y_1-x_2-y_2|+|x_1-y_1-x_2+y_2$$$| = max(|$$$x_1-x_2|, |y_1-y_2|$$$)

      Can you please prove why this is true?

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

        You forgot the $$$\dots*2$$$ from point V in the equation, maybe that was the problem in proving it?

        If you still struggle while remembering about $$$*2$$$, try to use the general fact that $$$|t|+|u| = max(|t+u|,|t-u|)$$$, then set $$$t=x_0+y_0-x_1-y_1$$$, $$$u=x_0-y_0-x_1+y_1$$$, like you wrote out.

        But it's easier to just draw it to be honest. :)

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

          Was not aware of this one:

          |t| + |u| = max(|t+u|, |t-u|)

          which is logical since it is just taking the max between the different sign combinations.

          It makes sense now, thank you!

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

        After letting a = x1-y1, b = x2-y2, you can simplify the expression by case-analysis 1) a >= b and 2) a < b to remove the absolute operator. In both cases, the LHS and RHS of your last equation satisfy LHS = 2*RHS

»
2 years ago, hide # |
Rev. 4  
Vote: I like it +64 Vote: I do not like it

There is a very simple solution for F (one without any data structures).

Solution
  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Such a clever observation and idea!!

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

    Neat.

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

    how did you come up with this : $$$\sum_{1 \leq i \lt j \leq N} \max{{{A_j - A_i, 0}}} = \sum_{1 \leq i \lt j \leq N} \left( \frac{|A_j - A_i| + (A_j - A_i)}{2} \right) $$$

    • »
      »
      »
      2 years ago, hide # ^ |
      Rev. 3  
      Vote: I like it +3 Vote: I do not like it

      If you realize that the $$$\max_{}:\mathbb{R}^2\to \mathbb{R}$$$ and "distance" $$$|\cdot-\cdot|:\mathbb{R}^2\to \mathbb{R}$$$ functions can be both computed by taking the cases on the maximum value then one might think that there could be a connection between the two. In fact there is the general formula

      $$$ \max_{} \{ a,b \}= \frac{|a-b|+(a+b)}{2}. $$$

      The formula might seem weird at first if you take the cases

      $$$ |a-b|=\left\{\begin{array}{ll} a-b,&a\geq b \\ b-a,& a \lt b \end{array}\right. $$$

      you can see how one could have come up with "the cancelation" trick in the formula.

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

    A little easier: Write $$$\max(A_j - A_i, 0) = \max(A_j, A_i) - A_i$$$. Then, the sum can be written as

    $$$\displaystyle \sum_{i = 1}^{N} \sum_{j = i + 1}^{N} \max(A_j, A_i) - A_i = \sum_{i = 1}^{N} \sum_{j = i + 1}^{N} \max(A_j, A_i) - \sum_{i = 1}^{N} \sum_{j = i + 1}^{N} A_i,$$$

    where the second sum is just the sum of $$$(N - i) \cdot A_i$$$ for all $$$1 \le i \le N$$$, and the first sum can be calculated using sorting (basically the same method as yours, but I think this is slightly more natural to think of).

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

    So nice trick!

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I spend 1 min thinking the solution of F and 4 min for coding after the round. Oops.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

You can check out video editorials of C, D, E, F if you are stuck

»
2 years ago, hide # |
 
Vote: I like it +36 Vote: I do not like it

Can somebody explain their solution for problem G?

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How can I approach problem E??

  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    • If you color the lattice points like a checkerboard pattern, note that the rabbit cannot switch colors. So we can split the points $$$(x, y)$$$ depending on the parity of $$$x+y$$$ and solve the problem independently for each.

    • Since the rabbit jumps diagonally we can think of changing our coordinate system, let the "x-direction" be the vector $$$(1, 1)$$$ and the "y-direction" be the vector $$$(-1, 1)$$$. This transformation turns the point $$$(x, y)$$$ into $$$(\frac{x+y}{2}, \frac{y-x}{2})$$$ and now the rabbit jumps one space horizontally or vertically. (Note: When dealing with the case where x+y is odd, you can shift the points one space in any direction to avoid fractions.)

    • Now, how do we find the total manhattan distance between each pair of points? You can solve this independently for total x distance and the total y distance.

    • For total x distance, sort the points by their x-coordinate and consider how many times each gap (in the x direction) between two points is added to the sum. It is the product of the number of points on the left and the number of points on the right. Do the same for y-coordinates.

    My solution: https://atcoder.jp/contests/abc351/submissions/52883361

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I did problem F using ordered set. I have one doubt how can fenwick tree be used to calculate the count of elements greater than a particular number? ( actually i'm trying to code after long time, some insight would really help!)

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

    You can use the Fencwick tree to store $$$\sum X_{j}$$$ $$$\forall$$$ $$$X_{j} \gt Y_{i}$$$ $$$i \in [0, N-1]$$$ and $$$j \in [i + 1, N-1]$$$. Then you can use the formula $$$\sum X_{j}$$$ — $$$cnt(X_{j} \gt Y_{i})$$$ $$$*$$$ $$$Y_{i}$$$. This works because all the values $$$ \lt =Y_{i}$$$ will contribute a $$$0$$$ to the answer. You can now reverse the array and do the operations for left side i.e for reversed array $$$j$$$ $$$\in$$$ $$$[0, i-1]$$$. Now counting elements $$$ \lt =$$$ some elements and finding their sum can be done using Fenwick Tree. You can coordinate compress the elements since storing them would give MLE but remember their original values. Now use compressed values to iterate in the Fenwick Tree and original values to store the sum in Fenwick Tree. Calculate all the values using the formula.

    Spoiler
»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
  • »
    »
    2 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You're creating a new 'vis' vector for every dfs call try optimising that.

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

I think it's terribly bad to design the corner case of 0 in problem G.I just submitted the code at the last 2 minutes of the contests,and WA on the last 2 tasks.This was a terrible experience for me.

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

too many manhattan

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

How to solve F using 2 ordered multisets. thanks