A12641 | Double Matrix
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given two $n \times m$ matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly increasing. A matrix is increasing if all rows are strictly increasing and all columns are strictly increasing.
For example, the matrix $\begin{bmatrix} 9&10&11\\ 11&12&14\\ \end{bmatrix}$ is increasing because each individual row and column is strictly increasing. On the other hand, the matrix $\begin{bmatrix} 1&1\\ 2&3\\ \end{bmatrix}$ is not increasing because the first row is not strictly increasing.
Let a position in the $i$ -th row (from top) and $j$ -th column (from left) in a matrix be denoted as $(i, j)$ .
In one operation, you can choose any two numbers $i$ and $j$ and swap the number located in $(i, j)$ in the first matrix with the number in $(i, j)$ in the second matrix. In other words, you can swap two numbers in different matrices if they are located in the corresponding positions.
You would like to make both matrices increasing by performing some number of operations (possibly none). Determine if it is possible to do this. If it is, print "Possible", otherwise, print "Impossible".
For example, the matrix $\begin{bmatrix} 9&10&11\\ 11&12&14\\ \end{bmatrix}$ is increasing because each individual row and column is strictly increasing. On the other hand, the matrix $\begin{bmatrix} 1&1\\ 2&3\\ \end{bmatrix}$ is not increasing because the first row is not strictly increasing.
Let a position in the $i$ -th row (from top) and $j$ -th column (from left) in a matrix be denoted as $(i, j)$ .
In one operation, you can choose any two numbers $i$ and $j$ and swap the number located in $(i, j)$ in the first matrix with the number in $(i, j)$ in the second matrix. In other words, you can swap two numbers in different matrices if they are located in the corresponding positions.
You would like to make both matrices increasing by performing some number of operations (possibly none). Determine if it is possible to do this. If it is, print "Possible", otherwise, print "Impossible".
输入格式
The first line contains two integers $n$ and $m$ ( $1 \leq n,m \leq 50$ ) — the dimensions of each matrix.
Each of the next $n$ lines contains $m$ integers $a_{i1}, a_{i2}, \ldots, a_{im}$ ( $1 \leq a_{ij} \leq 10^9$ ) — the number located in position $(i, j)$ in the first matrix.
Each of the next $n$ lines contains $m$ integers $b_{i1}, b_{i2}, \ldots, b_{im}$ ( $1 \leq b_{ij} \leq 10^9$ ) — the number located in position $(i, j)$ in the second matrix.
Each of the next $n$ lines contains $m$ integers $a_{i1}, a_{i2}, \ldots, a_{im}$ ( $1 \leq a_{ij} \leq 10^9$ ) — the number located in position $(i, j)$ in the first matrix.
Each of the next $n$ lines contains $m$ integers $b_{i1}, b_{i2}, \ldots, b_{im}$ ( $1 \leq b_{ij} \leq 10^9$ ) — the number located in position $(i, j)$ in the second matrix.
输出格式
Print a string "Impossible" or "Possible".
输入输出样例
输入 #1
2 2 2 10 11 5 9 4 3 12
输出 #1
Possible
输入 #2
2 3 2 4 5 4 5 6 3 6 7 8 10 11
输出 #2
Possible
输入 #3
3 2 1 3 2 4 5 10 3 1 3 6 4 8
输出 #3
Impossible
The first example, we can do an operation on the top left and bottom right cells of the matrices. The resulting matrices will be $\begin{bmatrix} 9&10\\ 11&12\\ \end{bmatrix}$ and $\begin{bmatrix} 2&4\\ 3&5\\ \end{bmatrix}$ .
In the second example, we don't need to do any operations.
In the third example, no matter what we swap, we can't fix the first row to be strictly increasing in both matrices.
In the second example, we don't need to do any operations.
In the third example, no matter what we swap, we can't fix the first row to be strictly increasing in both matrices.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted