11897 - Matrix Multiply   

Description

Given two matrix A and B, compute the sum of all elements in matrix A*B.

We will give you 2 instance of Matrix, you should use the provided functions to complete the task.

Followng are some explanations about the functions:

  • int *get_row(int row): this function will return a int* pointer that points to the elements in the row-th row of the matrix.
  • int *get_column(int col): this function will return a int* pointer that points to the elements in the col-th column of the matrix.
  • int get_size(): this function will return a int representing the size of the matrix (the matrix is of size*size).
  • void remove(int *array): you should call this function to free the array returned by the previous get_row() or get_column(), otherwise you won't pass the memory check. (If you can't pass our memory check, there might be some error message in the end of your output, this will cause a Wrong Answer.)

Your are required to implement the int calculate(Matrix A, Matrix B). This function will return the sum of all elements in matrix A*B.

Remember to #include "function.h" in the beginning of your code!

Input

First line of input is an integer n, indicating that both of the matrix is of size n*n.

For the next n lines, each line i will consists of n numbers, representing the elements in the i-th row of the first matrix.

For the next n lines, each line j will consists of n numbers, representing the elements in the j-th row of the second matrix.

It is guaranteed that:

  • Each element in the matrix won't exceed 20.
  • 2  n ≤ 100

Output

If you passed our memory check, the output will contain an integer representing the sum of the elements in matrix A*B.

Otherwise, there might be some error code, which is something that you should try to get rid of.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11897.cpp

Partial Judge Header

11897.h

Tags




Discuss