시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 38 | 20 | 14 | 50.000% |
For readability reason, the element of a matrix A at the a-th row and b-th column, Aa,b, will be written as (a, b). The matrix indices start at 1.
Given a matrix A of size N × N, two elements in the matrix (a, b) and (c, d) are called an exotic pair if all these three conditions are satisfied:
For example, given a matrix:
3 2 1 5 2 3 4 3 4
There are four exotic pairs in the matrix:
Among those four exotic pairs, (3, 1) and (3, 3) have the largest value (of 4); we call this kind of number as the largest exotic number.
Your task in this problem is to find the largest exotic number given a matrix, or output -1 if there is no such number.
The first line contains an integer: N (2 ≤ N ≤ 300) denoting the size of the matrix. The following N lines, each contains N integers (each separated by a single space): Ai,j (1 ≤ Ai,j ≤ 100,000) denoting the matrix element at i-th row and j-th column for 1 ≤ i ≤ N and 1 ≤ j ≤ N, respectively.
The output contains the largest exotic number for the given input, in a line. Output -1 if there is no such number.
3 3 2 1 5 2 3 4 3 4
4
4 3 2 1 4 4 2 1 4 5 1 2 1 3 1 5 6
5
2 1 2 2 4
-1
ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2017 G번