cswork / OA打开练习工作台

MetaOA #14

Diagonal Traverse (for E4 ;)

估计中等可在线判题

考点(AI 标注)模拟/实现原地数组

Starting from the top-left corner, traverse the diagonals in increasing order of the row-plus-column index sum. Even index sums go from bottom-left to top-right, and odd index sums go from top-right to bottom-left. Output the traversal sequence. The order in the original site's 3×3 example is wrong, so this site corrects it according to the standard alternating rule.

输入格式

This site's input scale: R C (1..100), followed by R lines of C integers each (−10⁹..10⁹).

输出格式

Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

样例 1

输入:

3 3
1 2 3
4 5 6
7 8 9

输出:

1 2 4 7 5 3 6 8 9

样例 2

输入:

2 2
1 2
3 4

输出:

1 2 3 4

样例 3

输入:

1 1
5

输出:

5

样例说明

Example 1: the diagonals output [1], [2,4], [7,5,3], [6,8], [9] in order, and concatenating them gives the result.