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

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

We will hold AtCoder Beginner Contest 351.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +52
  • Проголосовать: не нравится

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

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

GLHF!

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

I wish I could AC the first five questions.

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

Problem C was sh*t

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Such a clever observation and idea!!

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

    Neat.

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

    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 года назад, скрыть # ^ |
      Rev. 3  
      Проголосовать: нравится +3 Проголосовать: не нравится

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

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

    So nice trick!

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

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

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

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

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

Can somebody explain their solution for problem G?

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

How can I approach problem E??

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

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

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

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

too many manhattan

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

How to solve F using 2 ordered multisets. thanks