1. 程式人生 > >2018年上海金馬五校程式設計競賽 Problem O : ±1 Matrix

2018年上海金馬五校程式設計競賽 Problem O : ±1 Matrix

Time Limit: 5 s

Description

A matrix in mathematics is a rectangular array of numbers arranged in rows and columns. Given an n×m matrix A and an m×k matrix B, which only contain +1 and -1.

Please design a quick algorithm to calculate the result of multiplying these two matrices. Note that the result is an n

×kmatrix.

Input

There are multiple test cases (no more than 10).

For each test case, there are several lines.
The first line contains three integers nm and k (2 ≤ nmk < 1111), which correspond to the sizes of matrices A and Bdescribed above.
Next is a blank line.
The next n lines describe the matrix A

. Each of the n lines has m space-separated +1 or -1.
Next is a blank line.
The next m lines describe the matrix B. Each of the m lines has k space-separated +1 or -1.

There is a blank line between every two test cases, and there is no extra empty line at the beginning or end of the input.

Output

For each test case, output an n

×k matrix which is the result of multiplying matrices A and B.
You should output n lines. Each line contains k space-separated integers.

Sample Input

2 3 3

-1 -1 1
-1 1 -1

1 -1 1
1 1 1
1 1 1

2 2 2

-1 1
1 1

-1 -1
-1 1

Sample Output

-1 1 -1
-1 1 -1
0 2
-2 0