14605 - Matrix Operation   

Description

In this problem, you are asked to implement a class Matrix that represents a $N\times N$ Matrix.

Following are the methods you should implement:

  1. add A.add(B) → $A = A+B$
  2. subtract A.subtract(B) → $A = A-B$
  3. multiply A.multiply(B) → $A = AB$
  4. transpose A.transpose() → $A = A^{\top}$
  5. power A.power(x) → $\underbrace{AA \dots AA}_{\times x}$

Usefull links

Power of matrix:

Reference

Input

The first line contains two integers $N$, $T$, representing the size of the matrix and the number of the operations.

Following are $N$ lines, each line contains $N$ integers, representing the element in the starting matrix.

Following are $T$ operations, each operation start with an interger $o$, representings the type of the operation.

For operation type 1, 2, 3, interger $o$ is followed by $N\times N$ numbers, representing the element in the operand matrix.

For operation type 5, interger $o$ is followed by an interger $x$, repersentings $x$-th power.


Constraints

  • $1 \leq N \leq 10$
  • $1 \leq T \leq 1000$
  • $o = {1,2,3,4,5}$
  • $1 \leq x \leq 1e6$
  • All numbers would not exceed the range of long long.

Subtask

  1. (Testcases 1-6) $o = {1,2,3,4}$
  2. (Testcases 7-8) $1 \leq x \leq 5$
  3. (Testcases 9-10) No additional constraints.

Output

Output the final result of the matrix.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14605.cpp

Partial Judge Header

14605.h

Tags




Discuss