| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14605 | Matrix Operation |
|
| 14941 | Vending Mid |
|
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:
- add
A.add(B)→ $A = A+B$ - subtract
A.subtract(B)→ $A = A-B$ - multiply
A.multiply(B)→ $A = AB$ - transpose
A.transpose()→ $A = A^{\top}$ - power
A.power(x)→ $\underbrace{AA \dots AA}_{\times x}$
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
- (Testcases 1-6) $o = {1,2,3,4}$
- (Testcases 7-8) $1 \leq x \leq 5$
- (Testcases 9-10) No additional constraints.
Output
Output the final result of the matrix.
Sample Input Download
Sample Output Download
Partial Judge Code
14605.cppPartial Judge Header
14605.hTags
Discuss
Description
SpongeBob is hungry while waiting the bus. As a vending machine, now you want to sell the median-price kandy to SpongBob.
The Median Price is defined as the price of the element at index [(size - 1) / 2] in the sorted list of kandy prices.
If you have the following kandy prices: [10, 25, 40, 50], whose size is 4 and index is 0-based, then you should sell the kandy at index (size - 1) / 2 = 1.
If you have the following kandy prices: [10, 25, 40, 50, 100], whose size is 5 and index is 0-based, then you should sell the kandy at index (size - 1) / 2 = 2.
This is a partial judge probelm. Please implement these two functions:
-
store <price>: Add an item with a given price (integer) into the vending machine. -
sell: Sell the Median-Price kandy. If the machine is empty, ignore this command.
Constraints
- number of operations <= 2 * 105.
- price <= 109.
Please note that you CANNOT use STL to solve this problem.
Input
A sequence of commands (store <num> or sell).
Output
A single line containing two integers separated by a space:
-
The total number of items sold.
-
The total revenue with '\n'.