CF1042E.Vasya and Magic Matrix

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya has got a magic matrix aa of size n×mn \times m. The rows of the matrix are numbered from 11 to nn from top to bottom, the columns are numbered from 11 to mm from left to right. Let aija_{ij} be the element in the intersection of the ii-th row and the jj-th column.

Vasya has also got a chip. Initially, the chip is in the intersection of the rr-th row and the cc-th column (that is, in the element arca_{rc}). Vasya performs the following process as long as possible: among all elements of the matrix having their value less than the value of the element with the chip in it, Vasya randomly and equiprobably chooses one element and moves his chip to this element.

After moving the chip, he adds to his score the square of the Euclidean distance between these elements (that is, between the element in which the chip is now and the element the chip was moved from). The process ends when there are no elements having their values less than the value of the element with the chip in it.

Euclidean distance between matrix elements with coordinates (i1,j1)(i_1, j_1) and (i2,j2)(i_2, j_2) is equal to (i1−i2)2+(j1−j2)2\sqrt{(i_1-i_2)^2 + (j_1-j_2)^2}.

Calculate the expected value of the Vasya's final score.

It can be shown that the answer can be represented as PQ\frac{P}{Q}, where PP and QQ are coprime integer numbers, and Q≢0 (mod 998244353)Q \not\equiv 0~(mod ~ 998244353). Print the value P⋅Q−1P \cdot Q^{-1} modulo 998244353998244353.

瓦西娅得到了一个大小为 n×mn \times m 的魔法矩阵 aa。矩阵的行从上到下编号为 11 到 nn,列从左到右编号为 11 到 mm。令 aija_{ij} 表示第 ii 行与第 jj 列交叉处的元素。

瓦西娅还拥有一枚棋子。初始时,该棋子位于第 rr 行与第 cc 列的交叉处(即位于元素 arca_{rc})。瓦西娅重复执行如下过程,直到无法继续:在所有值严格小于当前棋子所在元素值的矩阵元素中,瓦西娅等概率地随机选择一个,并将棋子移动到该元素。

每次移动棋子后,他将本次移动的欧几里得距离的平方加到自己的得分中(即当前棋子所在位置与移动前位置之间的欧几里得距离的平方)。当不存在任何值严格小于当前棋子所在元素值的矩阵元素时,该过程结束。

坐标为 (i1,j1)(i_1, j_1) 与 (i2,j2)(i_2, j_2) 的矩阵元素之间的欧几里得距离定义为 (i1−i2)2+(j1−j2)2\sqrt{(i_1-i_2)^2 + (j_1-j_2)^2}。

请计算瓦西娅最终得分的期望值。

可以证明,答案总可表示为 PQ\frac{P}{Q} 的形式,其中 PP 与 QQ 是互质的整数,且 Q≢0(mod998244353)Q \not\equiv 0 \pmod{998244353}。请输出 P⋅Q−1 mod 998244353P \cdot Q^{-1} \bmod 998244353。

输入格式

The first line of the input contains two integers nn and mm (1≤n,m≤1 000)(1 \le n, m \le 1\,000) — the number of rows and the number of columns in the matrix aa.

The following nn lines contain description of the matrix aa. The ii-th line contains mm integers ai1,ai2,…,aim (0≤aij≤109)a_{i1}, a_{i2}, \dots, a_{im} ~ (0 \le a_{ij} \le 10^9).

The following line contains two integers rr and cc (1≤r≤n,1≤c≤m)(1 \le r \le n, 1 \le c \le m) — the index of row and the index of column where the chip is now.

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤1 0001 \le n, m \le 1\,000)—— 分别表示矩阵 aa 的行数和列数。

接下来的 nn 行描述矩阵 aa。其中第 ii 行包含 mm 个整数 ai1,ai2,…,aima_{i1}, a_{i2}, \dots, a_{im}(0≤aij≤1090 \le a_{ij} \le 10^9)。

接下来的一行包含两个整数 rr 和 cc(1≤r≤n, 1≤c≤m1 \le r \le n,\ 1 \le c \le m)—— 表示芯片当前所在的行号与列号。

输出格式

Print the expected value of Vasya's final score in the format described in the problem statement.

按题目描述的格式输出瓦西娅最终得分的期望值。

输入输出样例

  • 输入#1

    1 4
    1 1 2 1
    1 3

    输出#1

    2
  • 输入#2

    2 3
    1 5 7
    2 3 1
    1 2

    输出#2

    665496238

说明/提示

In the first example, Vasya will move his chip exactly once. The expected value of the final score is equal to 12+22+123=2\frac{1^2 + 2^2+ 1^2}{3} = 2.

在第一个例子中,瓦西娅将恰好移动他的棋子一次。最终得分的期望值等于 12+22+123=2\frac{1^2 + 2^2+ 1^2}{3} = 2。

输入解题思路,AI测评打分。不知道怎么写?

首页