No.1864 Shortest Paths Counting
タグ : / 解いたユーザー数 49
作問者 :
ぷら
shiomusubi496
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$
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もしくは右上の雲マークをクリックしてアカウントを作成してください。