222-Pooling
InterviewTime limit1sMemory limit256 MB
Repeatedly replace each 2x2 block of an NxN matrix with its second largest value until one number remains, and print it.
- Level
Medium4 of 10
- Topics
- Implementation, Simulation, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
Jonguk, who dreams of graduating early, was studying the deep learning that is popular these days. Inspired by the pooling operation of the convolutional neural network (CNN) commonly used in image processing, he invented his own pooling and decided to call it 222-pooling.
The following describes one application of 222-pooling to an 8×8 matrix.
-
Divide the matrix into 2×2 squares.

-
Keep only the second largest number in each square. The second largest number means the element a2 when the four elements of the square are ordered by size as a4 ≤ a3 ≤ a2 ≤ a1.

-
Step 2 reduces the size of the matrix.
Jonguk wonders what value remains when he applies 222-pooling repeatedly to an N×N matrix until its size becomes 1×1.
Mourning Jonguk, whose life has disappeared under the weight of lab work, let us answer his question for him.
Input
The first line gives N (2 ≤ N ≤ 1024). N is always a power of 2. (N=2K, 1 ≤ K ≤ 10)
Each of the next N lines gives the N elements of one row in order. Every entry of the matrix is an integer between -10,000 and 10,000 inclusive.
Output
Print the number that remains at the end.
Hint
For sample 2, the answer is obtained by continuing from the statement as shown below.
