alexjercan/bugnet huggingface dataset:
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;
    }
  }
  return 0;
}


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;
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define N 101
using namespace std;

int a[N][N], b[N][N];
long int c[N][N] = {{0}};

int main() {

  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 < l; j++) {
      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++) {
      cout << c[i][j];
      if (j != l - 1)
        cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#define N 1000
using namespace std;

int main() {

  int n, m, l;
  int a[N][N], b[N][N];
  int c[N][N] = {{0}};

  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++) {
      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++) {
      cout << c[i][j];
      if (j != j - 1)
        cout << " ";
    }
    cout << endl;
  }

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

#include <stdio.h>

int main() {
  long int A[101][101], B[101][101], C[101][101] = {0};
  int l, m, n;
  scanf("%d %d %d", &l, &m, &n);
  int h, i, j, k, g;
  for (i = 0; i <= l - 1; i++) {
    for (j = 0; j <= m - 2; j++) {
      scanf("%d ", &A[i][j]);
    }
    scanf("%d", &A[i][m - 1]);
  }
  for (i = 0; i <= m - 1; i++) {
    for (j = 0; j <= n - 2; j++) {
      scanf("%d ", &B[i][j]);
    }
    scanf("%d", &B[i][n - 1]);
  }
  for (h = 0; h <= l - 1; h++) {
    for (j = 0; j <= n - 1; j++) {
      for (k = 0; k <= m - 1; k++) {
        C[h][j] += A[h][k] * B[k][j];
      }
    }
  }
  for (i = 0; i <= l - 1; i++) {
    for (j = 0; j <= n - 2; j++) {
      printf("%ld ", C[i][j]);
    }
    printf("%ld\\n", C[i][n - 1]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int A[1000][1000], B[1000][1000], C[1000][1000] = {0};
  int l, m, n;
  scanf("%d %d %d", &l, &m, &n);
  int h, i, j, k, g;
  for (i = 0; i <= l - 1; i++) {
    for (j = 0; j <= m - 2; j++) {
      scanf("%d ", &A[i][j]);
    }
    scanf("%d", &A[i][m - 1]);
  }
  for (i = 0; i <= m - 1; i++) {
    for (j = 0; j <= n - 2; j++) {
      scanf("%d ", &B[i][j]);
    }
    scanf("%d", &B[i][n - 1]);
  }
  for (h = 0; h <= l - 1; h++) {
    for (j = 0; j <= n - 1; j++) {
      for (k = 0; k <= m - 1; k++) {
        C[h][j] += A[h][k] * B[k][j];
      }
    }
  }
  for (i = 0; i <= l - 1; i++) {
    for (j = 0; j <= n - 2; j++) {
      printf("%d ", C[i][j]);
    }
    printf("%d\\n", C[i][n - 1]);
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
#include <stack>
#include <stddef.h>
#include <string>

using namespace std;

int main() {
  int n, m, l;
  int a[101][101];
  int b[101][101];
  long long c[101][101];

  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++) {
      cout << c[i][j];
      if (j < l - 1)
        cout << ' ';
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <stack>
#include <stddef.h>
#include <string>

using namespace std;

int main() {
  int n, m, l;
  int a[101][101];
  int b[101][101];
  int c[101][101];

  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; i++) {
      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++) {
      cout << c[i][j];
      if (j < l - 1)
        cout << ' ';
    }
    cout << endl;
  }
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

int main() {

  int n, m, l;

  cin >> n >> m >> l;

  int **A = new int *[n];
  for (int i = 0; i < n; i++) {
    A[i] = new int[m];
  }

  int **B = new int *[m];
  for (int i = 0; i < m; i++) {
    B[i] = new int[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];
    }
  }

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

  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++) {
      cout << C[i][j];
      if (j == l - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }

  return (0);
}

Error: 0

Fixed submission:

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

int main() {

  int n, m, l;

  cin >> n >> m >> l;

  int **A = new int *[n];
  for (int i = 0; i < n; i++) {
    A[i] = new int[m];
  }

  int **B = new int *[m];
  for (int i = 0; i < n; i++) {
    B[i] = new int[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];
    }
  }

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

  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++) {
      cout << C[i][j];
      if (j == l - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }

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

#include <iostream>
using namespace std;
int main() {
  int n, m, l, num;
  cin >> n >> m >> l;
  int A[n][m], B[m][l];
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < m; b++) {
      cin >> num;
      A[a][b] = num;
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> num;
      B[a][b] = num;
    }
  }
  long long sum = 0;
  for (int a = 0; a < n; a++) {
    for (int c = 0; c < l; c++) {
      for (int b = 0; b < m; b++) {
        sum = sum + A[a][b] * B[b][c];
      }
      cout << sum;
      sum = 0;
      if (c != l - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, l, num;
  cin >> n >> m >> l;
  int A[n][m], B[m][l];
  for (int a = 0; a < 100000000000; a++) {
    for (int b = 0; b < m; b++) {
      cin >> num;
      A[a][b] = num;
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> num;
      B[a][b] = num;
    }
  }
  long long sum = 0;
  for (int a = 0; a < n; a++) {
    for (int c = 0; c < l; c++) {
      for (int b = 0; b < m; b++) {
        sum = sum + A[a][b] * B[b][c];
      }
      cout << sum;
      sum = 0;
      if (c != l - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int n, m, l;
  int **a, **b;
  long long **c;
  cin >> n >> m >> l;
  a = new int *[n];
  REP(i, n) {
    a[i] = new int[m];
    REP(j, m) { cin >> a[i][j]; }
  }

  b = new int *[m];
  REP(i, m) {
    b[i] = new int[l];
    REP(j, l) { cin >> b[i][j]; }
  }

  c = new long long *[n];
  REP(i, n) {
    c[i] = new long long[l];
    REP(j, l) {
      long long sum = 0;
      REP(k, m)
      sum += a[i][k] * b[k][j];
      c[i][j] = sum;
    }
  }

  REP(i, n) {
    REP(j, l) {
      if (j != 0)
        cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }

  REP(i, n)
  delete[] a[i];
  delete a;
  REP(i, m)
  delete[] b[i];
  delete b;
  REP(i, n)
  delete[] c[i];
  delete c;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int n, m, l;
  int **a, **b;
  long long **c;
  cin >> n >> m >> l;
  a = new int *[n];
  REP(i, n) {
    a[i] = new int[m];
    REP(j, m) { cin >> a[i][j]; }
  }

  b = new int *[m];
  REP(i, m) {
    b[i] = new int[l];
    REP(j, l) { cin >> b[i][j]; }
  }

  c = new long long *[n];
  REP(i, n) {
    c[i] = new long long[l];
    REP(j, l) {
      int sum = 0;
      REP(k, m)
      sum += a[i][k] * b[k][j];
      c[i][j] = sum;
    }
  }

  REP(i, l) {
    REP(j, l) {
      if (j != 0)
        cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }

  REP(i, n)
  delete[] a[i];
  delete a;
  REP(i, m)
  delete[] b[i];
  delete b;
  REP(i, n)
  delete[] c[i];
  delete c;

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main() {
  long int n, m, l, a[105][105], b[105][105]; // n*m,m*l,????????????,n*l
  while (cin >> n >> m >> l) {                //?????\\?¬¬????????°???
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= m; k++)
        cin >> a[i][k];

    //?????\\?¬¬????????°???
    for (int i = 1; i <= m; i++)
      for (int k = 1; k <= l; k++)
        cin >> b[i][k];
    //????????????
    long int c[105][105]; //?????????0
    memset(c, 0, 105 * 105 * sizeof(int));
    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 k = 1; k <= l; k++) {
        cout << c[i][k];
        if (k != l)
          cout << " ";
        if (k == l)
          cout << endl;
      }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main() {
  int n, m, l, a[100][100], b[100][100]; // n*m,m*l,????????????,n*l
  while (cin >> n >> m >> l) {           //?????\\?¬¬????????°???
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= m; k++)
        cin >> a[i][k];

    //?????\\?¬¬????????°???
    for (int i = 1; i <= m; i++)
      for (int k = 1; k <= l; k++)
        cin >> b[i][k];
    //????????????
    int c[100][100]; //?????????0
    memset(c, 0, 100 * 100 * sizeof(int));
    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 k = 1; k <= l; k++) {
        cout << c[i][k];
        if (k != l)
          cout << " ";
        if (k == l)
          cout << endl;
      }
  }
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#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: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  long long A[1000][1000], B[1000][1000], C[1000][1000];

  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;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long n, m, l, A[123][123], B[123][123], C[123][123];
int main() {
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int k = 0; k < l; k++) {
      cin >> B[j][k];
    }
  }
  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 k = 0; k < l; k++) {
      if (k == (l - 1)) {
        cout << C[i][k];
      } else {
        cout << C[i][k] << " ";
      }
    }
    cout << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, l, A[123][123], B[123][123], C[123][123];
int main() {
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int k = 0; k < l; k++) {
      cin >> B[j][k];
    }
  }
  while (1) {
    int s = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < l; k++) {
          s += (A[i][j] + B[j][k]);
          if ((A[i][j] + B[j][k]) == 0) {
            goto v;
          }
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < l; k++) {
        C[i][k] = s;
      }
    }
  }
v:;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < l; k++) {
      cout << C[i][k] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m, l;
  int i, j, k;
  long a[100][100];
  long b[100][100];
  long c[100][100];

  for (i = 0; i < 100; i++) {
    for (j = 0; j < 100; j++) {
      a[i][j] = 0;
      b[i][j] = 0;
      c[i][j] = 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] = c[i][j] + (a[i][k] * b[k][j]);
      }
    }
  }

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

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, l;
  int i, j, k;
  int a[100][100];
  int b[100][100];
  int c[100][100];

  cin >> n >> m >> l;

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

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

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

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

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

#include <iostream>
using namespace std;

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


Error: -11

Fixed submission:

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

int main() {
  long n, m, l, i, j, k, s, t, u, v, d;
  long A[10000][10000] = {}, B[10000][10000] = {}, C[10000][10000] = {};
  cin >> n >> m >> l;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (k = 0; k < m; k++) {
    for (s = 0; s < l; s++) {
      cin >> B[k][s];
    }
  }
  for (t = 0; t < n; t++) {
    for (u = 0; u < l; u++) {
      for (v = 0; v < m; v++) {
        C[t][u] += A[t][v] * B[v][u];
      }
      if (u == l - 1) {
        printf("%d", C[t][u]);
      } else {
        printf("%d ", C[t][u]);
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p02414 (C++) — buggy submission, verdict: Time Limit Exceeded

#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; 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;
    }
  }

  return 0;
}


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;
}
Problem p02414 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  long long a[100][100], b[100][100], c[100][100] = {};
  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 < l; j++) {
      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++) {
      cout << c[i][j];
      if (j < l - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long a[100][100], b[100][100], c[100][100];
  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 i = 1; i <= m; i++) {
    for (int j = 1; j <= l; j++) {
      cin >> b[i][j];
    }
  }
  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++) {
      cout << c[i][j];
      if (j < l)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}