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

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

int main() {
  int n, m;
  cin >> n >> m;
  vi player(m);
  rep(i, m) {
    cin >> player[i];
    player[i]--;
  }

  vi score(n, 0);
  rep(i, m) {
    int sum = 0;
    rep(j, n) {
      int a;
      cin >> a;
      a--;
      if (a != player[i])
        sum++;
      else
        score[j]++;
    }
    score[player[i]] += sum;
  }

  rep(i, n) cout << score[i] << endl;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

int main() {
  int n, m;
  cin >> n >> m;
  vi player(n);
  rep(i, m) {
    cin >> player[i];
    player[i]--;
  }

  vi score(n, 0);
  rep(i, m) {
    int sum = 0;
    rep(j, n) {
      int a;
      cin >> a;
      a--;
      if (a != player[i])
        sum++;
      else
        score[j]++;
    }
    score[player[i]] += sum;
  }

  rep(i, n) cout << score[i] << endl;
}
Problem p00532 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int a, s, d[1001][1001], g[1001], h[1001], i, j;
  scanf("%d", &a);
  scanf("%d", &s);
  for (i = 1; i <= s; i++) {
    scanf("%d", &g[i]);
  }
  for (i = 1; i <= s; i++) {
    for (j = 1; j <= a; j++) {
      scanf("%d", &d[i][j]);
    }
  }
  for (i = 1; i <= s; i++) {
    for (j = 1; j <= a; j++) {
      if (g[i] == d[i][j]) {
        h[j]++;
      } else {
        h[g[i]]++;
      }
    }
  }
  for (i = 1; i <= a; i++) {
    printf("%d\\n", h[i]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, s, d[10001][10001], g[10001], h[10001], i, j;
  scanf("%d", &a);
  scanf("%d", &s);
  for (i = 1; i <= s; i++) {
    scanf("%d", &g[i]);
  }
  for (i = 1; i <= s; i++) {
    for (j = 1; j <= a; j++) {
      scanf("%d", &d[i][j]);
    }
  }
  for (i = 1; i <= s; i++) {
    for (j = 1; j <= a; j++) {
      if (g[i] == d[i][j]) {
        h[j]++;
      } else {
        h[g[i]]++;
      }
    }
  }
  for (i = 1; i <= a; i++) {
    printf("%d\\n", h[i]);
  }
  return 0;
}
Problem p00532 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int point[100];
int main() {
  int n, m;
  cin >> n >> m;
  int a[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    a[i]--;
  }
  int b[n];
  for (int t = 0; t < m; t++) {
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      b[i]--;
      if (b[i] == a[t])
        point[i]++;
      else
        point[a[t]]++;
    }
  }
  for (int i = 0; i < n; i++)
    cout << point[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  int a[n];
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> point(n);
  for (int i = 0; i < m; i++) {
    int b[n];
    for (int j = 0; j < n; j++) {
      cin >> b[j];
      b[j]--;
      if (b[j] == a[i])
        point[j]++;
      else
        point[a[i]]++;
    }
  }
  for (int i = 0; i < n; i++)
    cout << point[i] << endl;
  return 0;
}
Problem p00532 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

struct before_main {
  before_main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} before_main;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a)                                                               \\
  { cout << #a << " = " << a << endl; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}

typedef long long ll;
int const inf = 1 << 29;

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  rep(i, M) cin >> A[i], A[i]--;

  vector<int> score(N);

  rep(i, M) {
    int X = 0;
    rep(j, N) {
      int x;
      cin >> x;
      x--;
      if (x == A[i])
        score[j]++;
      X += x != A[i];
    }
    score[A[i]] += X;
  }

  rep(i, N) { cout << score[i] << endl; }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

struct before_main {
  before_main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} before_main;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a)                                                               \\
  { cout << #a << " = " << a << endl; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}

typedef long long ll;
int const inf = 1 << 29;

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, M) cin >> A[i], A[i]--;

  vector<int> score(N);

  rep(i, M) {
    int X = 0;
    rep(j, N) {
      int x;
      cin >> x;
      x--;
      if (x == A[i])
        score[j]++;
      X += x != A[i];
    }
    score[A[i]] += X;
  }

  rep(i, N) { cout << score[i] << endl; }

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

#include <iostream>
#include <string>

using namespace std;

int main() {
  int h, w;
  char r[101][101];
  int e[101][101];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> r[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int k = j;
      while (true) {
        if (r[i][k] == 'c') {
          e[i][j] = j - k;
          break;
        }
        if (0 > k) {
          e[i][j] = -1;
          break;
        }
        k--;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << e[i][j];
      if (j < w - 1)
        cout << " ";
    }
    cout << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  int h, w;
  char r[100][100];
  int e[100][100];
  while (true) {

    cin >> h >> w;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> r[i][j];
        e[i][j] = 0;
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int k = j;
        while (true) {
          if (r[i][k] == 'c') {
            e[i][j] = j - k;
            break;
          }
          if (0 > k) {
            e[i][j] = -1;
            break;
          }
          k--;
        }
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cout << e[i][j];
      }
    }
  }
  return 0;
}
Problem p00533 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, w;
  char c;
  int ans[101][101];

  cin >> h >> w;

  for (int i = 0; i <= h; i++) {
    for (int j = 0; j <= w; j++) {
      ans[i][j] = -1;
    }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c;
      if (c == 'c')
        ans[i][j] = 0;
      else if (ans[i][j - 1] >= 0)
        ans[i][j] = ans[i][j - 1] + 1;
      else
        ans[i][j] = -1;
    }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w - 1; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << ans[i][w] << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int h, w;
  char c;
  int ans[100][100];

  cin >> h >> w;

  for (int i = 0; i <= h + 1; i++) {
    for (int j = 0; j <= w + 1; j++) {
      ans[i][j] = -1;
    }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c;
      if (c == 'c')
        ans[i][j] = 0;
      else if (ans[i][j - 1] >= 0)
        ans[i][j] = ans[i][j - 1] + 1;
      else
        ans[i][j] = -1;
    }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w - 1; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << ans[i][w] << endl;
  }
}
Problem p00533 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  char c;
  int w, h, k, i;
  scanf("%d %d", &h, &w);
  while (h--) {
    k = -1;
    for (i = 0; i < w; i++) {
      scanf(" %c", &c);
      if (c == 'c')
        k = 0;
      else if (k + 1)
        k++;
      if (i)
        printf(" ");
      printf("%d", k);
    }
    printf("\\n");
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main() {
  int h, w, n = 1, i, j, k, I, J;
  char str2[100][100];
  char str1[100][100];
  scanf("%d%d", &h, &w);
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      scanf("%s", &str1[i][j]);
    }
  }
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (str1[i][j] == 'c') {
        str2[i][j] = 'n';
        for (J = j; J < w; J++) {
          str2[i][j++] = n++;
        }
        for (k = 0; k < i; k++) {
          str2[i][j++] = '0';
        }

      } else {
        if (str2[i][j] == '.') {
          str2[i][j] = '-1';
        }
      }
    }
  }

  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      printf("%s", str2[i][j]);
    }
    printf("\\n");
  }
}
Problem p00533 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fo(i, a) for (i = 0; i < a; i++)
using namespace std;
int main(void) {
  int h, w, cnt = 0, i, j, a[101][101];
  char b[101][101];
  memset(a, -1, sizeof a);

  cin >> h >> w;
  fo(i, h) {
    cin >> b[i];
    fo(j, w) {
      if (b[i][j] == 'c') {
        a[i][j] = 0;
        cnt = 1;
      } else if (cnt >= 1) {
        a[i][j] = cnt;
        cnt++;
      }
    }
    cnt = 0;
  }
  fo(i, h) {
    fo(j, w) {
      cout << a[i][j];
      if (j == w - 1)
        break;
      cout << " ";
    }
    cout << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int main(void) {
  int h, w, con = 0;
  char c[100][100], d[100][100];
  string str;
  string::size_type index;

  cin >> h >> w;
  while (h > 0 && w > 0) {

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> c[i][j];
      }
    }

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        str = (c[i][j]);
        index = str.find("c");

        if (index != -1) {
          cout << 0 << " ";
          con = 1;
        }

        else if (index == -1 && con == 0) {
          cout << -1 << " ";
        }

        else {
          cout << con << " ";
          con++;
        }
      }
      cout << endl;
      con = 0;
    }
    cin >> h >> w;
  }

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


#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == 'c') {
        cout << 0;
      } else {
        bool b = true;
        for (int k = 1; k <= j; k++) {
          if (s[j - k] == 'c') {
            cout << k;
            b = false;
            break;
          }
        }
        if (b == true) {
          cout << -1;
        }
      }
      if (j != w - 1) {
        cout << " ";
      }
    }
    cout << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {

  int h, w;
  cin >> h >> w;

  for (int k = 0; k < h; k++) {

    for (int i = 0; i < w; i++) {
      string A;
      cin >> A;

      if (i = 0 && A[0] == 'c') {
        cout << 0;
      } else {
        cout << -1;
      }

      if (A[i] == 'c') {
        cout << " " << 0;
      } else {

        for (int j = 0; j < i; j++) {

          if (A[i - j + 1] == 'c') {
            cout << " " << j;
            break;
          }

          cout << " " << -1;
        }
      }
      cout << endl;
    }
  }

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

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

int main() {
  int H, W;
  while (~scanf("%d %d", &H, &W)) {
    char stage[101][101];
    for (int y = 0; y < H; y++) {
      int time = -1;
      bool has_cloud = false;
      char line[128];
      scanf("%s", line);
      for (int x = 0; x < W; x++) {
        stage[y][x] = line[x];
        if (stage[y][x] == 'c') {
          time = 0;
          has_cloud = true;
        }

        printf("%d%s", time, (x == W - 1 ? "" : " "));
        if (has_cloud) {
          time++;
        }
      }
      printf("\\n");
    }
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const double EPS = 1e-8;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

int main() {
  int H, W;
  while (~scanf("%d %d", &H, &W)) {
    int stage[101][101];
    for (int y = 0; y < H; y++) {
      int time = -1;
      bool has_cloud;
      for (int x = 0; x < W; x++) {
        scanf("%d", &stage[y][x]);
        if (stage[y][x] == 'c') {
          time = 0;
          has_cloud = true;
        }

        printf("%d%s", (x == W - 1 ? "" : " "));
        if (has_cloud) {
          time++;
        }
      }
      printf("\\n");
    }
  }
}
Problem p00533 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define PI 3.1415926

void swap(int *x, int *y) {
  int a = *x;
  int b = *y;
  *x = b;
  *y = a;
}
int factorial(int n);

int main() {
  int H, W, f[200][200] = {-1};
  int flag = 0;
  char s[200][200];
  scanf("%d %d", &H, &W);

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W + 1; j++) {
      scanf("%c", &s[i][j]);
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W + 1; j++) {
      for (int k = j; k >= 1; k--) {
        if (s[i][k] == 'c') {
          f[i][j] = j - k;
          flag = 1;
          break;
        }
        if (flag == 0) {
          f[i][j] = -1;
        }
        flag = 0;
      }
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 2; j <= W + 1; j++) {
      printf("%d", f[i][j]);
      if (j != W + 1) {
        printf(" ");
      }
    }
    printf("\\n");
  }
  return 0;
}

int factorial(int n) {
  if (n > 0) {
    return n * factorial(n - 1);
  } else {
    return 1;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cctype>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define PI 3.1415926

void swap(int *x, int *y) {
  int a = *x;
  int b = *y;
  *x = b;
  *y = a;
}
int factorial(int n);

int main() {
  int H, W, f[200][200] = {-2};
  char s[200][200];
  scanf("%d %d", &H, &W);
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      scanf("%c", &s[i][j]);
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      for (int k = j; k >= 1; k--) {
        f[i][j] += 1;
        if (s[i][j] == 'c') {
          break;
        }
      }
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; i <= H; j++) {
      printf("%d ", f[i][j]);
    }
    printf("\\n");
  }
  return 0;
}

int factorial(int n) {
  if (n > 0) {
    return n * factorial(n - 1);
  } else {
    return 1;
  }
}
Problem p00533 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {

  int h, w, f = 0;
  char c[120][120];
  int re[120][120];

  cin >> h >> w;

  for (int i = 0; i < h; i++) {
    f = 0;
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
      if (c[i][j] == 'c') {
        f = 1;
        re[i][j] = 0;
      } else {
        if (f != 1)
          re[i][j] = -1;
        else
          re[i][j] = re[i][j - 1] + 1;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    cout << re[i][0];
    for (int j = 1; j < w; j++)
      cout << " " << re[i][j];
    cout << endl;
  }
}

Error: 0

Fixed submission:

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

int H, W;
char c[500][500];
int re[500][500];

void search(int x, int y) {
  if (W <= x || c[y][x] == 'c')
    return;
  re[y][x] = re[y][x - 1] + 1;
  search(x + 1, y);
}

int main() {

  int k = 0;
  int x[500], y[500];

  cin >> H >> W;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> c[i][j];
      if (c[i][j] == 'c') {
        re[i][j] = 0;
        x[k] = j;
        y[k++] = i;
      } else if (c[i][j] == '.')
        re[i][j] = -1;
    }
  }

  for (int i = 0; i < k; i++)
    search((x[i] + 1), y[i]);

  for (int i = 0; i < H; i++) {
    cout << re[i][0];
    for (int j = 1; j < W; j++)
      cout << " " << re[i][j];
    cout << endl;
  }
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define INF (1 << 30)

int dp[1001][1001];

int main() {
  int n, m, d[1001], c[1001];
  fill(dp[0], dp[1001], INF);
  dp[0][0] = 0;

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> d[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> c[i];
  }

  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (dp[i][j] < INF) {
        if (dp[i + 1][j] > dp[i][j]) {
          dp[i + 1][j] = dp[i][j];
        }
        if (j < n && dp[i + 1][j + 1] > dp[i][j] + c[i + 1] * d[j + 1]) {
          dp[i + 1][j + 1] = dp[i][j] + c[i + 1] * d[j + 1];
        }
      }
    }
  }

  cout << dp[m][n] << endl;

  return 0;
}

Error: 0

Fixed submission:

// JOI14-quest4.cpp : Defines the entry point for the console application.
//

#include <stdio.h>

int dp[1001][1001] = {0};

int main(void) {
  int city_number, day, distance[1001], weather[1001];

  scanf("%d %d", &city_number, &day);

  for (int i = 0; i < city_number; i++) {
    scanf("%d", &distance[i]);
  }
  for (int i = 0; i < day; i++) {
    scanf("%d", &weather[i]);
  }

  dp[0][0] = 1;

  for (int i = 0; i <= day; i++) {
    for (int j = 0; j <= city_number; j++) {
      if (dp[i][j] != 0) {
        if (dp[i + 1][j] == 0) {
          dp[i + 1][j] = dp[i][j];
        } else {
          if (dp[i + 1][j] > dp[i][j]) {
            dp[i + 1][j] = dp[i][j];
          }
        }

        if (j < city_number) {
          if (dp[i + 1][j + 1] == 0) {
            dp[i + 1][j + 1] = dp[i][j] + (weather[i] * distance[j]);
          } else {
            if (dp[i + 1][j + 1] > dp[i][j] + (weather[i] * distance[j])) {
              dp[i + 1][j + 1] = dp[i][j] + (weather[i] * distance[j]);
            }
          }
        }
      }
    }
  }

  printf("%d\\n", dp[day][city_number] - 1);

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

#include <bits/stdc++.h>
using namespace std;
int d[1111], c[1111];
int n, m;
int memo[1111][1111];
int solve(int day, int tosi) {
  if (tosi == n) {
    return 0;
  }
  if (day == m) {
    return 1000000000;
  }
  if (memo[day][tosi])
    return memo[day][tosi];
  int ret = 0;
  ret += min(solve(day + 1, tosi + 1) + d[tosi] * c[day], solve(day + 1, tosi));
  return memo[day][tosi] = ret;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i];
  }

  cout << solve(0, 0) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int d[1001], c[1001];
int n, m;
int solve(int day, int tosi) {
  if (tosi == n) {
    return 0;
  }
  if (day == m) {
    return 10000000;
  }
  int ret = 0;
  ret += min(solve(day + 1, tosi + 1) + d[tosi] * c[day], solve(day + 1, tosi));
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i];
  }
  cout << solve(0, 0) << endl;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
using namespace std;
#define max 1000000000
int main() {
  int m, n;
  int dp[1100][1100], dis[1100], weather[1100];
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &dis[i]);
  }
  for (int j = 1; j <= m; j++) {
    scanf("%d", &weather[j]);
  }
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= n; j++) {
      if (i <= m - n && j == 0) {
        dp[i][j] = 0;
      } else if (i < j) {
        dp[i][j] = max;
      } else if (i - j >= n) {
        dp[i][j] = max;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + weather[i] * dis[j]);
    }
  }
  printf("%d\\n", dp[m][n]);
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
#define max 10000000
int main() {
  int m, n;
  int dp[10000][10000], dis[10000], weather[10000];
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &dis[i]);
  }
  for (int j = 1; j <= m; j++) {
    scanf("%d", &weather[j]);
  }
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= n; j++) {
      if (i <= m - n && j == 0) {
        dp[i][j] = 0;
      } else if (i < j) {
        dp[i][j] = max;
      } else if (i - j >= n) {
        dp[i][j] = max;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + weather[i] * dis[j]);
    }
  }
  printf("%d\\n", dp[m][n]);
  return 0;
}