A12164 | Vasya and Magic Matrix
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has got a magic matrix $a$ of size $n \times 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 $a_{ij}$ 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 $a_{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 $(i_1, j_1)$ and $(i_2, j_2)$ is equal to $\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 $\frac{P}{Q}$ , where $P$ and $Q$ are coprime integer numbers, and $Q \not\equiv 0~(mod ~ 998244353)$ . Print the value $P \cdot Q^{-1}$ modulo $998244353$ .
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 $a_{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 $(i_1, j_1)$ and $(i_2, j_2)$ is equal to $\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 $\frac{P}{Q}$ , where $P$ and $Q$ are coprime integer numbers, and $Q \not\equiv 0~(mod ~ 998244353)$ . Print the value $P \cdot Q^{-1}$ modulo $998244353$ .
输入格式
The first line of the input contains two integers $n$ and $m$ $(1 \le n, m \le 1\,000)$ — 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 $a_{i1}, a_{i2}, \dots, a_{im} ~ (0 \le a_{ij} \le 10^9)$ .
The following line contains two integers $r$ and $c$ $(1 \le r \le n, 1 \le c \le m)$ — the index of row and the index of column where the chip is now.
The following $n$ lines contain description of the matrix $a$ . The $i$ -th line contains $m$ integers $a_{i1}, a_{i2}, \dots, a_{im} ~ (0 \le a_{ij} \le 10^9)$ .
The following line contains two integers $r$ and $c$ $(1 \le r \le n, 1 \le c \le 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 $\frac{1^2 + 2^2+ 1^2}{3} = 2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted