Loading...
Loading...
You are given four lists of integers rowSizesA, colSizesA, rowSizesB, colSizesB and two 2D lists of integers blockValuesA and blockValuesB. They describe two block-constant matrices A and B. The matrix A has sum(rowSizesA) rows, sum(colSizesA) columns, and is partitioned into len(rowSizesA)*len(colSizesA) blocks. Block (i,j) has rowSizesA[i] rows and colSizesA[j] columns with every entry equal to blockValuesA[i][j]. The matrix B is described by rowSizesB, colSizesB, and blockValuesB in the same way.
The product C = A * B is the usual matrix product. C is also block-constant: its blocks have rows given by rowSizesA[i] and columns given by colSizesB[j]. Return blockValuesC, the 2D list of block values of C, so that every entry in block (i, j) equals blockValuesC[i][j]. Mod each entry of blockValuesC by 10 ** 9 + 7 before returning.
You can assume the matrices can be multiplied: sum(colSizesA) == sum(rowSizesB).
rowSizesA.length ≤100colSizesA.length ≤100rowSizesB.length ≤100colSizesB.length ≤100blockValuesA.length = rowSizesA.lengthblockValuesA[i].length = colSizesA.length for every iblockValuesB.length = rowSizesB.lengthblockValuesB[i].length = colSizesB.length for every irowSizesA[i] ≤109colSizesA[i] ≤109rowSizesB[i] ≤109colSizesB[i] ≤109sum(rowSizesA) ≤109sum(colSizesA) ≤109sum(rowSizesB) ≤109sum(colSizesB) ≤109sum(colSizesA) = sum(rowSizesB)blockValuesA[i][j] ≤109+6blockValuesB[i][j] ≤109+6A is a 2 by 2 matrix with every entry 3, and B is a 2 by 2 matrix with every entry 4. Each entry of the product is 24.
A has rows [1,2] and [3,4] in its two row blocks, while B has rows [5,6,6] and [7,8,8]. The product has block values [[19,22],[43,50]].
If we decompress matrix A we obtain [[1,1,2,2],[1,1,2,2],[3,3,4,4],[3,3,4,4]], and the same for B. Multiplying gives [[14,14,20,20],[14,14,20,20],[30,30,44,44],[30,30,44,44]].
Every row of A is [1,2,2] and the only column of B is [3,3,4]. The single product block is 1*3 + 2*3 + 2*4 = 17.