AtCoder Regular Contest 158
E
All Pair Shortest Paths
AtCoder
⌀ 2641
原题
← DF →
翻译中…

Problem Statement

翻译中…

We have a grid with $2$ rows and $N$ columns. Let $(i,j)$ denote the square at the $i$-th row from the top and $j$-th column from the left. $(i,j)$ has a postive integer $x_{i,j}$ written on it.

翻译中…

Two squares are said to be adjacent when they share a side.

翻译中…

A path from square $X$ to $Y$ is a sequence $(P_1, \ldots, P_n)$ of distinct squares such that $P_1 = X$, $P_n = Y$, and $P_i$ and $P_{i+1}$ are adjacent for every $1\leq i \leq n-1$. Additionally, the weight of that path is the sum of integers written on $P_1, \ldots, P_n$.

翻译中…

For two squares $X$ and $Y$, let $f(X, Y)$ denote the minimum weight of a path from $X$ to $Y$. Find the sum of $f(X, Y)$ over all pairs of squares $(X,Y)$, modulo $998244353$.

翻译中…

Constraints

翻译中…
  • $1\leq N\leq 2\times 10^5$
  • $1\leq x_{i,j} \leq 10^9$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
x_{1,1} \ldots x_{1,N}
x_{2,1} \ldots x_{2,N}

翻译中…

Output

翻译中…

Print the sum of $f(X, Y)$ over all pairs of squares $(X,Y)$, modulo $998244353$.

翻译中…

样例

Input #1
1
3
5
Output #1
24
You should find the sum of the following four values. - For $X = (1,1), Y = (1,1)$: $f(X, Y) = 3$. - For $X = (1,1), Y = (2,1)$: $f(X, Y) = 8$. - For $X = (2,1), Y = (1,1)$: $f(X, Y) = 8$. - For $X = (2,1), Y = (2,1)$: $f(X, Y) = 5$.
Input #2
2
1 2
3 4
Output #2
76
Input #3
5
1 1000000000 1 1 1
1 1 1 1000000000 1
Output #3
66714886
题目信息
题号
arc158_e
时间限制
4 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。