## #2284597

Solution for ITP1_7_D: Matrix Multiplication by hiroyuking

Source Code Status Test Cases
Policy: public     Reviewed: 59
00.22 sec    61452 KB    98 lines     2232 bytes    2017-04-26 16:19
```import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.Stream;

import java.util.Set;
import java.util.HashSet;

public class Main {

public static void main(String[] args) {
try {
List<String> lines = new ArrayList<String>();
String line = "";

}
br.close();

Integer n, m, l = 0;
n = Integer.parseInt(lines.get(0).split(" ")[0]);
m = Integer.parseInt(lines.get(0).split(" ")[1]);
l = Integer.parseInt(lines.get(0).split(" ")[2]);

Long[][] A = new Long[n][m];
Long[][] b = new Long[m][l];
Long[][] C = new Long[n][l];

for (int i=1; i<n+1; i++) {
String[] elements = lines.get(i).split(" ");
for (int j=0; j<m; j++) {
A[i-1][j] = Long.parseLong(elements[j]);
}
}
for (int i=n+1; i<n+m+1; i++) {
String[] elements = lines.get(i).split(" ");
for (int j=0; j<l; j++) {
b[i-n-1][j] = Long.parseLong(elements[j]);
}
}

//          [l]
//      __________
//      |  |  |  |
//	    |  |  |  |
// [n]  |  |  |  |
//      |--|--|--|
//
for (int i=0; i<n; i++) {
for (int j=0; j<l; j++) {
C[i][j] = 0L;
}
}

for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
for (int k=0; k<l; k++) {
//System.out.print(String.format("%d * %d ,", A[i][j], b[j][k]));
Long x = A[i][j] * b[j][k];
C[i][k] += x;
}
}
}

for (int i=0; i<n; i++) {
for (int j=0; j<l; j++) {
if (j == l-1) {
System.out.println(C[i][j]);
} else {
System.out.print(C[i][j] + " ");
}
}
}

System.exit(0);

} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(Arrays.toString(e.getStackTrace()));
System.exit(0);
}
}
}

```
 Compile Error Logs: You are not authorized to see the message.

Status
 Judge: 18/18 JAVA CPU: 00.22 sec Memory: 61452 KB Length: 2232 B 2017-04-26 16:19 2017-04-26 16:19
Results for testcases
 Case # Verdict CPU Time Memory In Out Case Name Case #1: : Accepted 00.04 sec 24312 KB Case #2: : Accepted 00.04 sec 24264 KB Case #3: : Accepted 00.04 sec 24248 KB Case #4: : Accepted 00.04 sec 24424 KB Case #5: : Accepted 00.05 sec 24436 KB Case #6: : Accepted 00.05 sec 24168 KB Case #7: : Accepted 00.04 sec 24288 KB Case #8: : Accepted 00.04 sec 24212 KB Case #9: : Accepted 00.04 sec 24136 KB Case #10: : Accepted 00.04 sec 24188 KB Case #11: : Accepted 00.04 sec 24292 KB Case #12: : Accepted 00.04 sec 24384 KB Case #13: : Accepted 00.06 sec 25188 KB Case #14: : Accepted 00.08 sec 27796 KB Case #15: : Accepted 00.06 sec 25044 KB Case #16: : Accepted 00.08 sec 27828 KB Case #17: : Accepted 00.22 sec 61452 KB Case #18: : Accepted 00.21 sec 61204 KB
 < prev | / | next >

 Judge Input #  ( | ) Judge Output #  ( | )