Shuffled Matrix

We are to read and write a square matrix of integers. It is to be
written with the standard layout but it is given to us differently, with
disordered rows and omitting some of them.

Input

The first line of the input provides us with a nonnegative integer, the
dimension n of the matrix. Then, the second line gives a nonnegative
integer m indicating the number of row specifications provided
explicitly along the next lines. Then we have m lines: in each of them,
the first number i is always such that 1 ≤ i ≤ n and indicates that the
line specifies row i; this number is followed by n integers that form
indeed the i-th row of the matrix. No assumption can be made about the
values i beyond what has been indicated. In case the same row index
appears multiple times, only the last one is to be considered valid.
Rows that are not explicitly specified are understood to consist only of
zeros.

Output

The square matrix specified by the input, written row by row: the
contents of row i is given by the last line starting by i in the input,
if any, and is just zeros if no specification for that row appears in
the input.

Problem information

Author: José Luis Balcázar

Generation: 2026-01-25T17:11:35.497Z

© Jutge.org, 2006–2026.
https://jutge.org
