CF1042E.Vasya and Magic Matrix
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya has got a magic matrix a of size n×m . The rows of the matrix are numbered from 1 to n from top to bottom, the columns are numbered from 1 to m from left to right. Let aij be the element in the intersection of the i -th row and the j -th column.
Vasya has also got a chip. Initially, the chip is in the intersection of the r -th row and the c -th column (that is, in the element arc ). 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) and (i2,j2) is equal to (i1−i2)2+(j1−j2)2 .
Calculate the expected value of the Vasya's final score.
It can be shown that the answer can be represented as QP , where P and Q are coprime integer numbers, and Q≡0 (mod 998244353) . Print the value P⋅Q−1 modulo 998244353 .
输入格式
The first line of the input contains two integers n and m (1≤n,m≤1000) — the number of rows and the number of columns in the matrix a .
The following n lines contain description of the matrix a . The i -th line contains m integers ai1,ai2,…,aim (0≤aij≤109) .
The following line contains two integers r and c (1≤r≤n,1≤c≤m) — the index of row and the index of column where the chip is now.
输出格式
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 312+22+12=2 .