CF954C.Matrix Walk
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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:
- (i + 1, j) — only if i < x;
- (i, j + 1) — only if j < y;
- (i - 1, j) — only if i > 1;
- (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?
存在一个大小为 x×y 的整数矩阵 A。对每个 1≤i≤x、1≤j≤y,有 Ai,j=y(i−1)+j。显然,区间 [1..xy] 中的每个整数在该矩阵中恰好出现一次。
你在该矩阵中遍历了一条路径。该路径可描述为一个已访问格子序列 a1,a2,…,an,表示你从包含数字 a1 的格子出发,接着移动到包含数字 a2 的格子,依此类推。
从位于第 i 行、第 j 列的格子(记作 (i,j))出发,你可以移动至以下格子之一:
- (i+1,j) —— 仅当 i<x 时允许;
- (i,j+1) —— 仅当 j<y 时允许;
- (i−1,j) —— 仅当 i>1 时允许;
- (i,j−1) —— 仅当 j>1 时允许。
注意:每次移动必须到达一个相邻格子,不允许停留在当前格子。你并不确切知道 x 和 y 的值,但你需要找出任意一组满足条件的 x 和 y,使得你能从包含整数 a1 的格子出发,一步移动到包含 a2 的格子,再一步移动到包含 a3 的格子,依此类推。你能否选择 x 和 y,使其与你的移动序列不矛盾?
输入格式
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 ≤ 109) — the integers in the cells on your path.
第一行包含一个整数 $ n ( 1 \leq n \leq 200000 $)—— 表示你在路径上访问的格子数量(若某个格子被访问了两次,则该格子在序列中出现两次)。
第二行包含 $ n $ 个整数 $ a_1, a_2, \dots, a_n ( 1 \leq a_i \leq 10^9 $)—— 表示路径上各格子中的整数。
输出格式
If all possible values of x and y such that 1 ≤ x, y ≤ 109 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 109.
如果所有满足 1≤x,y≤109 的 x 和 y 的可能取值均与关于你的路径的信息矛盾,则输出 NO。
否则,第一行输出 YES,第二行输出满足条件的 x 和 y 的值,使得在具有该行数和列数的矩阵中,你的路径是可能的。注意:x 和 y 必须是不超过 109 的正整数。
输入输出样例
输入#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.
第一个测试用例中的矩阵及其上的路径如下所示:

此外,第一个和第三个样例均存在多个正确答案。
输入解题思路,AI测评打分。不知道怎么写?