alexjercan/bugnet huggingface dataset:
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;

typedef struct {
  int row;
  int col;
  vector<vector<long>> val;
} matrix;

void init_matrix(matrix &mat, int nrow, int ncol);
void read_matrix(matrix &mat);
void matrix_mult(const matrix &mat_a, const matrix &mat_b, matrix &mat_c);
void print_matrix(const matrix &mat);

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  matrix a, b, c;

  init_matrix(a, n, m);
  init_matrix(b, m, l);
  init_matrix(c, n, l);

  read_matrix(a);
  read_matrix(b);
  matrix_mult(a, b, c);
  print_matrix(c);
}

void init_matrix(matrix &mat, int nrow, int ncol) {
  mat.row = nrow;
  mat.col = ncol;
  mat.val.resize(nrow);
  for (auto &vec : mat.val) {
    vec.resize(ncol, 0);
  }
}

void read_matrix(matrix &mat) {
  for (int row = 0; row != mat.row; ++row) {
    for (int col = 0; col != mat.col; ++col) {
      cin >> mat.val[row][col];
    }
  }
}

void matrix_mult(const matrix &a, const matrix &b, matrix &c) {
  auto n = a.row;
  auto m = a.col;
  auto l = b.col;
  for (int col = 0; col != n; ++col) {
    for (int row = 0; row != l; ++row) {
      for (int i = 0; i != m; ++i) {
        c.val[col][row] += a.val[col][i] * b.val[i][row];
      }
    }
  }
}

void print_matrix(const matrix &mat) {
  for (const auto &row : mat.val) {
    int i = 0;
    for (const auto &aij : row) {
      cout << aij;
      if (++i != mat.col)
        cout << ' ';
    }
    cout << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

typedef struct {
  int row;
  int col;
  vector<vector<long>> val;
} matrix;

void init_matrix(matrix &mat, int nrow, int ncol);
void read_matrix(matrix &mat);
void matrix_mult(const matrix &mat_a, const matrix &mat_b, matrix &mat_c);
void print_matrix(const matrix &mat);

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  matrix a, b, c;

  init_matrix(a, n, m);
  init_matrix(b, m, l);
  init_matrix(c, n, l);

  read_matrix(a);
  read_matrix(b);
  matrix_mult(a, b, c);
  print_matrix(c);
}

void init_matrix(matrix &mat, int nrow, int ncol) {
  mat.row = nrow;
  mat.col = ncol;
  mat.val.resize(nrow);
  for (auto vec : mat.val) {
    vec.resize(ncol);
  }
}

void read_matrix(matrix &mat) {
  for (int row = 0; row != mat.row; ++row) {
    for (int col = 0; col != mat.col; ++col) {
      cin >> mat.val[row][col];
    }
  }
}

void matrix_mult(const matrix &a, const matrix &b, matrix &c) {
  auto n = a.row;
  auto m = a.col;
  auto l = b.col;
  for (int col = 0; col != n; ++col) {
    for (int row = 0; row != l; ++row) {
      for (int i = 0; i != m; ++i) {
        c.val[col][row] += a.val[col][i] * b.val[i][row];
      }
    }
  }
}

void print_matrix(const matrix &mat) {
  for (auto row : mat.val) {
    int i = 0;
    for (auto aij : row) {
      cout << aij;
      if (++i != mat.col)
        cout << ' ';
    }
    cout << endl;
  }
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#define V 100
int main() {
  int i, j, k;
  int n, m, l;
  int a[V][V], b[V][V];
  long int c[V][V];

  scanf("%d %d %d", &n, &m, &l);

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      a[i][j] = 0;
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      b[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      c[i][j] = 0;
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      scanf("%d", &b[i][j]);
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      if (j == 0) {
        printf("%li", c[i][j]);
      } else {
        printf("% li", c[i][j]);
      }
    }
    printf("\\n");
  }
}


Error: TLE

Fixed submission:

#include <stdio.h>
#define V 100
int main() {
  int i, j, k;
  int n, m, l;
  int a[V][V], b[V][V];
  long int c[V][V];

  scanf("%d %d %d", &n, &m, &l);

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      a[i][j] = 0;
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      b[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      c[i][j] = 0;
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      scanf("%d", &b[i][j]);
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      if (j = 0) {
        printf("%li", c[i][j]);
      } else {
        printf("% li", c[i][j]);
      }
    }
    printf("\\n");
  }
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long n, m, l;
  long A[100][100], B[100][100], C[100][100];

  cin >> n >> m >> l;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      C[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int k = 0; k < m; k++) {
      cin >> A[i][k];
    }
  }

  for (int k = 0; k < m; k++) {
    for (int j = 0; j < l; j++) {
      cin >> B[k][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int k = 0; k < m; k++) {
      for (int j = 0; j < l; j++) {

        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l - 1; j++) {

      cout << C[i][j] << " ";
    }
    cout << C[i][l - 1] << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long n, m, l;
  long A[100][100], B[100][100], C[100][100];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      C[i][j] = 0;
    }
  }

  cin >> n >> m >> l;

  for (int i = 0; i < n; i++) {
    for (int k = 0; k < m; k++) {
      cin >> A[i][k];
    }
  }

  for (int k = 0; k < m; k++) {
    for (int j = 0; j < l; j++) {
      cin >> B[k][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int k = 0; k < m; k++) {
      for (int j = 0; j < l; j++) {

        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      cout << C[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

#define N 1000

typedef long long int lli;

lli a[N * N];
lli b[N * N];
lli c[N * N];

int n, m, l;

void mult() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < l; j++)
      for (int k = 0; k < m; k++)
        c[i * N + j] += a[i * N + k] * b[k * N + j];
}

int main(void) {
  scanf("%d%d%d", &n, &m, &l);

  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      scanf("%lld", &a[i * N + j]);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++)
      scanf("%lld", &b[i * N + j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < l; j++)
      c[i * N + j] = 0;

  mult();

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l - 1; j++)
      printf("%lld ", c[i * N + j]);
    printf("%lld", c[i * N + l - 1]);
    printf("\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

#define N 10000

int a[N * N];
int b[N * N];
int c[N * N];

int n, m, l;

void mult() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < l; i++)
      for (int k = 0; k < m; k++)
        c[i * N + j] += a[i * N + k] * b[k * N + j];
}

int main(void) {
  int n, m, l;
  scanf("%d%d%d", &n, &m, &l);

  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; i++)
      scanf("%d", &a[i * N + j]);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; i++)
      scanf("%d", &b[i * N + j]);

  mult();

  for (int i = 0; i < l; i++) {
    for (int j = 0; j < l; i++)
      printf("%d ", c[i * N + j]);
    printf("\\n");
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m, l, b[100][100], a[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < l; k++) {
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1)
        cout << c[i][j] << " ";
      else
        cout << c[i][j] << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m, l;
  long long A[100][100], B[100][100], C[100][100] = {};
  cin >> n >> m >> l;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m;) {
      for (int k = 0; k < l; k++) {
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1)
        cout << C[i][j] << " ";
      else
        cout << C[i][j] << endl;
    }
  }

  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  long int n, m, l, a[100][100], b[100][100], r[100][100], i, j, k;
  for (i = 0; i < 100; i++) {
    for (j = 0; j < 100; j++) {
      a[i][j] = 0;
      b[i][j] = 0;
      r[i][j] = 0;
    }
  }
  cin >> n >> m >> l;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] > 10000) {
        cout << " Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      cin >> b[i][j];
      if (b[i][j] > 10000) {
        cout << "Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        r[i][j] += (a[i][k] * b[k][j]);
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      cout << r[i][j];
      if (j != l - 1)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long int n, m, l, a[100][100], b[100][100], r[100][100], i, j, k;
  for (i = 0; i < 100; i++) {
    for (j = 0; j < 100; j++) {
      a[i][j] = 0;
      b[i][j] = 0;
      r[i][j] = 0;
    }
  }
  cin >> n >> m >> l;
  if (n < 100 || m < 100 || l < 100) {
    cout << "Too Large" << endl;
    return 1;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] > 10000) {
        cout << " Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      cin >> b[i][j];
      if (b[i][j] > 10000) {
        cout << "Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        r[i][j] += (a[i][k] * b[k][j]);
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      cout << r[i][j];
      if (j != l - 1)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  long long A[100][100]{0};
  long long B[100][100]{0};
  long long C[100][100]{0};
  int n, m, l;
  cin >> n >> m >> l;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < l; ++j) {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < l; ++k) {
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < l; ++j) {
      cout << C[i][j];
      if (j != l - 1)
        cout << ' ';
    }
    cout << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int A[100][100]{0};
  int B[100][100]{0};
  int C[100][100]{0};
  int n, m, l;
  cin >> n >> m >> l;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < l; ++j) {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < l; ++k) {
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < l; ++l) {
      cout << C[i][j];
      if (j != l - 1)
        cout << ' ';
    }
    cout << endl;
  }

  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  int i, j, k;
  int A[100][100], B[100][100];
  long C[100][100] = {0};

  cin >> n >> m >> l;

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      cout << C[i][j];
      if (j != l - 1) {
        cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  int i, j, k;
  int A[100][100], B[100][100];
  long C[100][100] = {0};

  cin >> n >> m >> l;

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (j = 0; j < m; j++) {
        cin >> A[i][j];
      }
    }
  }

  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      for (j = 0; j < l; j++) {
        cin >> B[i][j];
      }
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      cout << C[i][j];
      if (j != l - 1) {
        cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, v, sum = 0, ar[101][101], b[101][101], r, c;
  while (cin >> r >> c >> v) {
    for (i = 0; i < r; i++) {
      for (j = 0; j < c; j++) {
        cin >> ar[i][j];
      }
    }
    for (i = 0; i < c; i++) {
      for (j = 0; j < v; j++) {
        cin >> b[i][j];
      }
    }
    for (i = 0; i < r; i++) {
      for (j = 0; j < v; j++) {
        for (k = 0; k < c; k++) {
          sum = sum + ar[i][k] * b[k][j];
        }
        if (j == v - 1) {
          cout << sum;
        } else {
          cout << sum << " ";
        }
        sum = 0;
      }
      cout << endl;
    }
    sum = 0;
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, v, sum = 0, ar[10000][10000], b[10000][10000], r, c;
  while (scanf("%d%d%d", &r, &c, &v) != EOF) {
    for (i = 0; i < r; i++) {
      for (j = 0; j < c; j++) {
        cin >> ar[i][j];
      }
    }

    for (i = 0; i < c; i++) {
      for (j = 0; j < v; j++) {
        cin >> b[i][j];
      }
    }

    for (i = 0; i < r; i++) {
      for (j = 0; j < v; j++) {
        for (k = 0; k < c; k++) {
          sum = sum + ar[i][k] * b[k][j];
        }
        cout << sum << " ";
        sum = 0;
      }
      cout << endl;
    }
  }
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int A[100][100], B[100][100];
  long long int C[1000][1000];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> B[a][b];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  for (int c = 0; c < n; c++) {
    for (int d = 0; d < l - 1; d++) {
      cout << C[c][d] << " ";
    }
    cout << C[c][l - 1] << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int A[10000][10000], B[10000][10000], C[10000][10000];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> B[a][b];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  for (int c = 0; c < n; c++) {
    for (int d = 0; d < l - 1; d++) {
      cout << C[c][d] << " ";
    }
    cout << C[c][l - 1] << endl;
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  long a[105][105], b[105][105], c[105][105] = {{0}};
  int n, m, l;

  cin >> n >> m >> l;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int k = 1; k <= l; k++) {
      cin >> b[j][k];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      for (int k = 1; k <= m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      if (j == 1)
        cout << c[i][j];
      else
        cout << " " << c[i][j];
    }
    cout << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long a[100][100], b[100][100], c[100][100] = {{0}};
  int n, m, l;

  cin >> n >> m >> l;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int k = 1; k <= l; k++) {
      cin >> b[j][k];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      for (int k = 1; k <= m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      if (j == 1)
        cout << c[i][j];
      else
        cout << " " << c[i][j];
    }
    cout << endl;
  }

  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int n, m, l;
  long matA[100][100] = {};
  long matB[100][100] = {};
  long ans[100][100] = {};
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> matA[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++)
      cin >> matB[i][j];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        ans[i][j] += matA[i][k] * matB[k][j];
      }
      cout << ans[i][j];
      if (j != l - 1)
        cout << " ";
      if (j == l - 1)
        cout << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int n, m, l;
  int matA[100][100] = {};
  int matB[100][100] = {};
  int ans[100][100] = {};
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> matA[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++)
      cin >> matB[i][j];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; m++) {
        ans[i][j] += matA[i][m] * matB[m][j];
      }
      cout << ans[i][j];
      cout << (j == l - 1) ? "" : " ";
      if (j == l - 1)
        cout << endl;
    }
  }

  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  long long a[100][100], b[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      c[i][j] = 0;
      for (int k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j)
        cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  long long a[100][100], b[100][100], c[100][100];
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; m++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; m++) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      c[i][j] = 0;
      for (int k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j)
        cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long int n, m, l, A[100][100], B[100][100], C[100][100] = {};
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < l; k++) {
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1)
        cout << C[i][j] << " ";
      else
        cout << C[i][j] << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long int n, m, l, A[100][100], B[100][100], C[100][100] = {};
  cin >> n >> m >> l;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m;) {
      for (int k = 0; k < l; k++) {
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1)
        cout << C[i][j] << " ";
      else
        cout << C[i][j] << endl;
    }
  }

  return 0;
}