fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Trimat {
  6. int Size;
  7. int[][] M;
  8.  
  9. public Trimat(int n, Scanner in) {
  10. Size = n;
  11. M = new int[Size][];
  12. for (int k = 0; k < Size; k++) {
  13. M[k] = new int[Size - k];
  14. for (int j = 0; j < Size - k; j++)
  15. M[k][j] = in.nextInt();
  16. }
  17. }
  18.  
  19. public Trimat(int n, int a) {
  20. Size = n;
  21. M = new int[Size][];
  22. for (int k = 0; k < Size; k++) {
  23. M[k] = new int[Size - k];
  24. M[k][0] = a;
  25. }
  26. }
  27.  
  28. public void print() {
  29. for (int k = 0; k < Size; k++) {
  30. for (int j = 0; j < k; j++)
  31. System.out.print("\t");
  32. for (int j = 0; j < Size - k; j++)
  33. System.out.format("%d\t", M[k][j]);
  34. System.out.println();
  35. }
  36. }
  37.  
  38. public Trimat add(Trimat B) {
  39. Trimat C = new Trimat(Size, 0);
  40. for (int k = 0; k < Size; k++)
  41. for (int j = 0; j < Size - k; j++)
  42. C.M[k][j] = M[k][j] + B.M[k][j];
  43. return C;
  44. }
  45.  
  46. public Trimat mul(Trimat B) {
  47. Trimat C = new Trimat(Size, 0);
  48. for (int k = 0; k < Size; k++)
  49. for (int j = k; j < Size; j++)
  50. for (int r = k; r <= j; r++)
  51. C.M[k][j-k] += M[k][r-k] * B.M[r][j-r];
  52. return C;
  53. }
  54. }
  55.  
  56. class Main
  57. {
  58. public static void main (String[] args) throws java.lang.Exception
  59. {
  60. Scanner in = new Scanner(System.in);
  61. int n = in.nextInt();
  62.  
  63. Trimat A = new Trimat(n, in), B = new Trimat(n, in);
  64. Trimat I = new Trimat(n,1);
  65. Trimat C = A.mul(I.add(B.mul(B)));
  66. A.print();
  67. B.print();
  68. C.print();
  69. }
  70. }
Success #stdin #stdout 0.15s 321280KB
stdin
3
2 2 2
0 3
1
1 2 3
   4 5
      6
stdout
2	2	2	
	0	3	
		1	
1	2	3	
	4	5	
		6	
4	54	236	
	0	111	
		37