問題一覧 > 通常問題

No.2573 moving up

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 23
作問者 : aplysiaSheep / テスター : deuteridayo 👑 AngrySadEight Magentor ragna
お気に入りにしたユーザー ProblemId : 10401 / 自分の提出
問題文最終更新日: 2023-12-02 08:19:49
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
緑以下コンテスト Extra (順位表) の他の問題:

Problem Statement

There is a board as shown in the figure below.
The board has $H$ rows. Row $i$ contains $i + W - 1$ cells, and the $j$-th cell from the left in row $i$ has coordinates $(i, j)$.
Each cell is adjacent to the cells in the $6$ surrounding directions.
More strictly, the cell $(i, j)$ is adjacent to each of the cells $(i-1, j-1)$, $(i-1, j)$, $(i, j-1)$, $(i, j+1)$, $(i+1, j)$, $(i+1, j+1)$, as long as the cell exists.
On this board, $W$ pieces are placed. Piece $k$ is initially placed at $(x_k, y_k)$.

You may perform the following operation any number of times.

  • Choose one piece and move it to an adjacent cell, paying a cost of $1$. (Multiple pieces may be on the same cell. Also, a piece cannot be moved outside the board.)

  • Find the minimum cost required to reach a state in which the pieces are placed one each on the $W$ cells of row $1$.

    Constraints

    • $1≤H, W≤200$
    • $1≤x_i≤H$
    • $1≤y_i≤W + x_i - 1$
    • $(x_i, y_i)$ are pairwise distinct
    • All input values are integers

    Input

    $H\ W$
    $x_1\ y_1$
    $x_2\ y_2$
    $\vdots$        
    $x_W\ y_W$
    

    Output

    Output the minimum cost.

    Sample

    Sample 1
    Input
    3 2
    3 4
    3 1
    
    Output
    4
    

    Moving as shown in the figure is optimal, and the minimum cost required is 4.
    Sample 2
    Input
    3 2
    2 1
    3 1
    
    Output
    4
    

    Moving as shown in the figure is optimal. Note that the pieces must be placed one each on the cells of the top row.
    Sample 3
    Input
    4 10
    1 4
    1 7
    1 10
    3 2
    3 4
    3 5
    3 7
    4 2
    4 7
    4 8
    
    Output
    19
    

    提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。