CF1004D.Sonya and Matrix
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.
Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers have the form of a rhombus, that is why Sonya called this type so.
The Manhattan distance between two cells ( x1 , y1 ) and ( x2 , y2 ) is defined as ∣x1−x2∣+∣y1−y2∣ . For example, the Manhattan distance between the cells (5,2) and (7,1) equals to ∣5−7∣+∣2−1∣=3 .
Example of a rhombic matrix.Note that rhombic matrices are uniquely defined by n , m , and the coordinates of the cell containing the zero.
She drew a n×m rhombic matrix. She believes that you can not recreate the matrix if she gives you only the elements of this matrix in some arbitrary order (i.e., the sequence of n⋅m numbers). Note that Sonya will not give you n and m , so only the sequence of numbers in this matrix will be at your disposal.
Write a program that finds such an n×m rhombic matrix whose elements are the same as the elements in the sequence in some order.
输入格式
The first line contains a single integer t ( 1≤t≤106 ) — the number of cells in the matrix.
The second line contains t integers a1,a2,…,at ( 0≤ai<t ) — the values in the cells in arbitrary order.
输出格式
In the first line, print two positive integers n and m ( n×m=t ) — the size of the matrix.
In the second line, print two integers x and y ( 1≤x≤n , 1≤y≤m ) — the row number and the column number where the cell with 0 is located.
If there are multiple possible answers, print any of them. If there is no solution, print the single integer −1 .
输入输出样例
输入#1
20 1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4
输出#1
4 5 2 2
输入#2
18 2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1
输出#2
3 6 2 3
输入#3
6 2 1 0 2 1 2
输出#3
-1
说明/提示
You can see the solution to the first example in the legend. You also can choose the cell (2,2) for the cell where 0 is located. You also can choose a 5×4 matrix with zero at (4,2) .
In the second example, there is a 3×6 matrix, where the zero is located at (2,3) there.
In the third example, a solution does not exist.