A11767 | Matrix Walk
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a matrix $A$ of size $x×y$ filled with integers. For every ,  $A_{i,j}=y(i-1)+j$ . Obviously, every integer from $[1..xy]$ occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells $a_{1}$ , $a_{2}$ , ..., $a_{n}$ denoting that you started in the cell containing the number $a_{1}$ , then moved to the cell with the number $a_{2}$ , and so on.
From the cell located in $i$ -th line and $j$ -th column (we denote this cell as $(i,j)$ ) you can move into one of the following cells:
1. $(i+1,j)$ — only if $i<x$ ;
2. $(i,j+1)$ — only if $j<y$ ;
3. $(i-1,j)$ — only if $i>1$ ;
4. $(i,j-1)$ — only if $j>1$ .
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know $x$ and $y$ exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer $a_{1}$ , then move to the cell containing $a_{2}$ (in one step), then move to the cell containing $a_{3}$ (also in one step) and so on. Can you choose $x$ and $y$ so that they don't contradict with your sequence of moves?
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells $a_{1}$ , $a_{2}$ , ..., $a_{n}$ denoting that you started in the cell containing the number $a_{1}$ , then moved to the cell with the number $a_{2}$ , and so on.
From the cell located in $i$ -th line and $j$ -th column (we denote this cell as $(i,j)$ ) you can move into one of the following cells:
1. $(i+1,j)$ — only if $i<x$ ;
2. $(i,j+1)$ — only if $j<y$ ;
3. $(i-1,j)$ — only if $i>1$ ;
4. $(i,j-1)$ — only if $j>1$ .
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know $x$ and $y$ exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer $a_{1}$ , then move to the cell containing $a_{2}$ (in one step), then move to the cell containing $a_{3}$ (also in one step) and so on. Can you choose $x$ and $y$ so that they don't contradict with your sequence of moves?
输入格式
The first line contains one integer number $n$ ( $1<=n<=200000$ ) — the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=10^{9}$ ) — the integers in the cells on your path.
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=10^{9}$ ) — the integers in the cells on your path.
输出格式
If all possible values of $x$ and $y$ such that $1<=x,y<=10^{9}$ contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values $x$ and $y$ such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding $10^{9}$ .
Otherwise, print YES in the first line, and in the second line print the values $x$ and $y$ such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding $10^{9}$ .
输入输出样例
输入 #1
8 1 2 3 6 9 8 5 2
输出 #1
YES 3 3
输入 #2
6 1 2 1 2 5 3
输出 #2
NO
输入 #3
2 1 10
输出 #3
YES 4 9
The matrix and the path on it in the first test looks like this:
Also there exist multiple correct answers for both the first and the third examples.
Also there exist multiple correct answers for both the first and the third examples.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted