← 返回 capitalone 的题目列表Sort Every Border Layer of a Matrix Clockwise
类型:online_judge
Given an n × m integer matrix matrix, partition it into concentric border layers:
Layer 0 is the outer border.
Layer 1 is the next border after removing the outer border.
Continue until every element belongs to a layer.
For every layer:
Starting from the layer's top-left corner, extract its border elements in clockwise order.
Sort the extracted values in nondecreasing order.
Write the sorted values back along the same clockwise traversal, starting from the same top-left corner.
Return the resulting matrix.
A degenerate inner layer containing one row, one column, or one cell must also be processed in its natural left-to-right or top-to-bottom order.
Input Format
First line: integers n m.
Next n lines: m integers describing the matrix.
Output Format
Print the resulting matrix, one row per line, with space-separated values.
Constraints
1 <= n, m <= 200
-10^9 <= matrix[i][j] <= 10^9
Example
Input
1 1
5
Output
5