問題一覧 > 通常問題

No.1864 Shortest Paths Counting

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 49
作問者 : Chippppp / テスター : ぷら shiomusubi496
お気に入りにしたユーザー ProblemId : 7343 / 自分の提出
問題文最終更新日: 2022-03-20 11:14:46
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
yukicoder contest 334 (順位表) の他の問題:

Problem Statement

There are $N$ distinct points on a two-dimensional plane, numbered from $1$ to $N$. The coordinates of point $i$ are $(X_i, Y_i)$.

The distance between $(x_0, y_0)$ and $(x_1, y_1)$ is defined as $\max(|x_0 - x_1|, |y_0 - y_1|)$.

Find the number of routes that travel from point $1$ to point $N$ via some points and minimize the total distance traveled.
More precisely, find the number of sequences $p$ of positive integers of length $k$ satisfying $p_1 = 1$, $p_k = N$, $1 \leq p_i \leq N$ $(1 \leq i \leq k)$ and $p_i \neq p_{i+1}$ $(1 \leq i \leq k - 1)$ (added at 22:35) that minimize $\displaystyle\sum_{i = 1}^{k - 1} \max(|X_{p_{i + 1}} - X_{p_i}|, |Y_{p_{i + 1}} - Y_{p_i}|)$.
Since the answer can be very large, output it modulo $998244353$.

Input

$N$
$X_1$ $Y_1$
$X_2$ $Y_2$
$\vdots$
$X_N$ $Y_N$

  • $2 \le N \le 2 \times 10 ^ 5$
  • $-10 ^ 9 \le X_i, Y_i \le 10 ^ 9$ $(1 \le i \le N)$
  • $(X_i, Y_i) \neq (X_j, Y_j)$ $(i \neq j)$
  • All input values are integers.
  • Output

    Output the number of ways of moving that minimize the total distance, modulo $998244353$.
    Also, output a newline at the end.

    Sample

    Sample 1
    Input
    3
    0 0
    0 1
    1 2
    Output
    2

    The following $2$ routes satisfy the condition.

    • Point $1$ $\to$ Point $3$
    • Point $1$ $\to$ Point $2$ $\to$ Point $3$

    For example, in route number $2$ of the list, the total distance is $\max(|0-0|, |0-1|) + \max(|0-1|, |2-1|) = 1 + 1 = 2$.

    Sample 2
    Input
    5
    0 6
    1 5
    3 2
    5 5
    3 0
    Output
    4

    The following $4$ routes satisfy the condition.

    • Point $1$ → Point $5$
    • Point $1$ → Point $2$ → Point $5$
    • Point $1$ → Point $3$ → Point $5$
    • Point $1$ → Point $2$ → Point $3$ → Point $5$
    Sample 3
    Input
    10
    -8 1
    3 -5
    -4 8
    5 -4
    -1 -6
    6 0
    -1 -4
    2 -9
    -6 7
    10 -9
    Output
    14

    Sample 4
    Input
    14
    0 0
    7 -7
    11 -3
    9 -1
    7 1
    7 -5
    10 -2
    8 0
    4 4
    5 1
    5 3
    7 -3
    6 2
    12 -4
    
    Output
    334

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