Matrix Zigzag - MarisaOJ: Marisa Online Judge

Matrix Zigzag

Time limit: 1000 ms
Memory limit: 256 MB
Given an $n \times m$ matrix, print the elements in diagonal zigzag order, starting from position $(1,1)$ and ending at position $(n,m)$. For example:
### Input - The first line contains two integers, $n$ and $m$. - The next $n$ lines each contain $m$ integers representing the matrix. ### Output - Print $n$ integers as the answer. ### Constraints - $1 \le n, m \le 50$. - $1 \le A_i \le 100$ ### Example Input: ``` 3 3 1 2 3 4 5 6 7 8 9 ``` Output: ``` 1 2 4 7 5 3 6 8 9 ```