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

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

int main() {

  int n, m;

  cin >> n >> m;

  vector<int> d, c;

  d.resize(n);
  c.resize(m);

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

  int dp[1001][1001];

  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = 1000000000;

  for (int i = 0; i <= m; i++)
    dp[i][0] = 0;

  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      dp[i][j] = min(dp[i - 1][j - 1] + d[j - 1] * c[i - 1], dp[i - 1][j]);

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

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int n, m;
vector<int> d, c;
int mincost = 2000000000;
int count = 0;

struct set {
  int cost, day, site;
};
queue<set> Q;

void dfs(int co, int da, int si) {
  count++;
  //    cout << co <<" " <<  da <<" " << si << endl;
  if (si == n && mincost > co && da <= m)
    mincost = co;
  if ((m - da) - (n - si) > 0 && co <= mincost)
    Q.push((set){co, da + 1, si});
  if (co < mincost && si < n && da < m)
    Q.push((set){co + d[si] * c[da], da + 1, si + 1});
}

int main() {

  cin >> n >> m;

  d.resize(n);
  c.resize(m);

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

  Q.push((set){0, 0, 0});
  set t;
  while (!Q.empty()) {
    t = Q.front();
    Q.pop();
    dfs(t.cost, t.day, t.site);
  }

  cout << mincost << endl;
  //  cout << count << endl;
}
Problem p00534 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int INF = 100010001000;

int n, m, cost[1010], miti[1010], memo[1010][1010];

int a(int day, int basho) {
  if (memo[day][basho] >= 0)
    return memo[day][basho];
  else if (basho == n)
    return 0;
  else if (day == m)
    return INF;
  else {
    return memo[day][basho] =
               min(a(day + 1, basho + 1) + cost[day] * miti[basho],
                   a(day + 1, basho));
  }
}

signed main() {
  memset(cost, 0, sizeof(cost));
  memset(miti, 0, sizeof(miti));
  memset(memo, -1, sizeof(memo));
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> miti[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> cost[j];
  }
  cout << a(0, 0) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

const int INF = 100010001000;

int n, m, cost[1010], miti[1010], memo[1010][1010];

int a(int day, int basho) {
  if (memo[day][basho] > -1)
    return memo[day][basho];
  else if (basho == n)
    return 0;
  else if (day == m)
    return INF;
  else {
    return min(a(day + 1, basho + 1) + cost[day] * miti[basho],
               a(day + 1, basho));
  }
}

signed main() {
  memset(cost, 0, sizeof(cost));
  memset(miti, 0, sizeof(miti));
  memset(memo, -1, sizeof(memo));
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> miti[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> cost[j];
  }
  cout << a(0, 0) << endl;
  return 0;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(a, b) (a = min(a, b))
using namespace std;

const int INF = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> d(n), c(m);
  rep(i, n) cin >> d[i];
  rep(i, m) cin >> c[i];

  vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF));
  dp[0][0] = 0;

  rep(i, n) {
    rep(j, m) {
      chmin(dp[i][j + 1], dp[i][j]);
      chmin(dp[i + 1][j + 1], dp[i][j] + d[i] * c[j]);
    }
  }

  cout << *min_element(dp[n].begin(), dp[n].end()) << endl;
}

Error: -6
free(): invalid pointer


Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(a, b) (a = min(a, b))
using namespace std;

const int INF = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> d(n), c(m);
  rep(i, n) cin >> d[i];
  rep(i, m) cin >> c[i];

  vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF));
  dp[0][0] = 0;

  rep(i, n) {
    rep(j, m + 1) {
      chmin(dp[i][j + 1], dp[i][j]);
      if (j < m)
        chmin(dp[i + 1][j + 1], dp[i][j] + d[i] * c[j]);
    }
  }

  cout << *min_element(dp[n].begin(), dp[n].end()) << endl;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int a, b, c[1001], d[1001], i, j, e[1001][1001], f[1001][1001], x, m;
int main(void) {
  scanf("%d %d", &a, &b);
  for (i = 0; i <= 1000; i++) {
    c[i] = 0;
    d[i] = 0;
  }
  for (i = 0; i <= 1000; i++) {
    for (j = 0; j <= 1000; j++) {
      f[i][j] = 0;
    }
  }
  for (i = 1; i <= a; i++) {
    scanf("%d", &c[i]);
  }
  for (i = 1; i <= b; i++) {
    scanf("%d", &d[i]);
  }
  for (i = 0; i <= b; i++) {
    for (j = 0; j <= a; j++) {
      if (c[i + 1] * d[j + 1] + f[i][j] < f[i + 1][j + 1] ||
          f[i + 1][j + 1] == 0) {
        if (j <= i && b >= i + 1 && a >= j + 1) {
          f[i + 1][j + 1] = f[i][j] + c[j + 1] * d[i + 1];
        }
      }
      if (f[i][j] + c[j + 1] * d[i + 1] > f[i][j + 1] || f[i + 1][j + 1] == 0) {
        if (j <= i && b >= i + 1 && a >= j + 1 && f[i][j + 1] != 0) {
          f[i + 1][j + 1] = f[i][j + 1];
        }
      }
    }
  }
  printf("%d\\n", f[b][a]);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int a, b, c[1001], d[1001], i, j, e[1001][1001], f[1001][1001], x, m;
int main(void) {
  scanf("%d %d", &a, &b);
  for (i = 0; i <= 1000; i++) {
    c[i] = 0;
    d[i] = 0;
  }
  for (i = 0; i <= 1000; i++) {
    for (j = 0; j <= 1000; j++) {
      f[i][j] = 0;
    }
  }
  for (i = 1; i <= a; i++) {
    scanf("%d", &c[i]);
  }
  for (i = 1; i <= b; i++) {
    scanf("%d", &d[i]);
  }
  for (i = 0; i <= b; i++) {
    for (j = 0; j <= a + 1; j++) {
      if (c[i + 1] * d[j + 1] + f[i - 1][j - 1] < f[i + 1][j + 1] ||
          f[i + 1][j + 1] == 0) {
        if (j < i && b >= i + 1 && a >= j + 1) {
          f[i + 1][j + 1] = f[i][j] + c[j + 1] * d[i + 1];
          if (f[i + 1][j + 1] > f[i][j + 1] && f[i][j + 1] != 0) {
            f[i + 1][j + 1] = f[i][j + 1];
          }
        }
      }
    }
  }
  printf("%d\\n", f[b][a]);
  return 0;
}
Problem p00534 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int memo[1005][1005], n, m, strain[1005], dis[1005], ans;
int solve(int dp, int days);

int main() {
  for (int i = 0; i < n; i++)
    strain[i] = 0, dis[i] = 0;
  fill(memo[0], memo[1005], -1);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> dis[i];
  for (int i = 0; i < m; i++)
    cin >> strain[i];

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

int solve(int dp, int days) {
  if (n == dp)
    return 0;
  else {
    if (days == m)
      return 100010001000;
    if (memo[dp][days] != -1)
      return memo[dp][days];
    return memo[dp][days] =
               min(solve(dp + 1, days + 1) + strain[days] * dis[dp],
                   solve(dp, days + 1));
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int memo[1005][1005], n, m, strain[1005], dis[1005], tt = 0, ans = 1000000000;
void solve(int dp, int sum, int days);

int main() {
  fill(memo[0], memo[1004], 100000000);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> dis[i];
  for (int i = 0; i < m; i++)
    cin >> strain[i];
  solve(0, 0, 0);
  cout << ans << endl;
  // cout << tt;
  return 0;
}

void solve(int dp, int sum, int days) {
  // tt++;
  if (dp == n) {
    ans = min(ans, sum);
    // cout << sum << endl;
    return;
  } else {
    if (m == days)
      return;
    if (memo[dp][days] <= sum)
      return;
    solve(dp + 1, sum + strain[days] * dis[dp], days + 1);
    solve(dp, sum, days + 1);
  }
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
int za[1001][1001];
using namespace std;
int main(void) {
  int i, j, d[1001], c[1001], n, m, hirodo, min;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++)
    scanf("%d", &d[i]);
  for (i = 0; i < m; i++)
    scanf("%d", &c[i]);
  for (i = 0; i <= m; i++) {
    for (j = 0; j <= n; j++) {
      za[i][j] = 2100000000;
    }
  }
  za[0][0] = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j <= n; j++) {
      if (za[i][j] < za[i + 1][j])
        za[i + 1][j] = za[i][j];
      hirodo = c[i] * d[j];
      if (za[i][j] + hirodo < za[i + 1][j + 1] && j <= n)
        za[i + 1][j + 1] = za[i][j] + hirodo;
    }
  }
  /*for(i=0;i<=m;i++) {
          for(j=0;j<=n;j++) {
                  printf("%d          ",za[i][j]);
          }
          printf("\\n");
  }*/
  min = 2100000000;
  for (i = 0; i <= m; i++)
    if (min > za[i][n])
      min = za[i][n];
  printf("%d\\n", min);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
int za[1000][1000];
using namespace std;
int main(void) {
  int i, j, d[1000], c[1000], n, m, hirodo, min;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++)
    scanf("%d", &d[i]);
  for (i = 0; i < m; i++)
    scanf("%d", &c[i]);
  for (i = 0; i <= m; i++) {
    for (j = 0; j <= n; j++) {
      za[i][j] = 2100000000;
    }
  }
  za[0][0] = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j <= n; j++) {
      if (za[i][j] < za[i + 1][j])
        za[i + 1][j] = za[i][j];
      hirodo = c[i] * d[j];
      if (za[i][j] + hirodo < za[i + 1][j + 1])
        za[i + 1][j + 1] = za[i][j] + hirodo;
    }
  }
  /*for(i=0;i<=m;i++) {
          for(j=0;j<=n;j++) {
                  printf("%d          ",za[i][j]);
          }
          printf("\\n");
  }*/
  min = 2100000000;
  for (i = 0; i <= m; i++)
    if (min > za[i][n])
      min = za[i][n];
  printf("%d\\n", min);
  return 0;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

#define MAX_N 1100
#define MAX_M 1100

int main() {
  int dp[MAX_N + 1][MAX_M + 1];
  int n, m, s, x[MAX_N], y[MAX_M];
  memset(dp, 127, sizeof(dp));
  memset(x, 127, sizeof(x));
  memset(y, 127, sizeof(y));
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> y[i];
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + x[j + 1] * y[i + 1]);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

#define MAX_N 3000
#define MAX_M 3000

int main() {
  int dp[MAX_N + 1][MAX_M + 1];
  int n, m, s, x[MAX_N], y[MAX_M];
  memset(dp, 127, sizeof(dp));
  memset(x, 127, sizeof(x));
  memset(y, 127, sizeof(y));
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> y[i];
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + x[j + 1] * y[i + 1]);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
static const int INF = 1e9;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  vector<int> c(m);
  rep(i, m) cin >> c[i];
  // dp[???????????°???????????????][?????\\???]
  int dp[1001][1001];
  rep(i, 1001) rep(j, 1001) dp[i][j] = INF; //?????????
  rep(i, m) dp[0][i] = 0;                   //?????????
  reps(i, 1, n + 1) {
    rep(j, m) {
      //?????????
      dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + d[i - 1] * c[j]);
    }
  }
  int ans = INF;
  //?????????????°???????????????¢???
  rep(i, m) { ans = min(ans, dp[n][i]); }
  printf("%d\\n", ans);
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

#define loop(i, n) for (int i = 0; i < n; i++)
#define INM 114514

using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  loop(i, m) {
    loop(j, n) { dp[i][j] = INM; }
  }
  vector<int> d(n + 1);
  vector<int> c(m + 1);
  loop(i, n) { cin >> d[i]; }
  loop(i, m) { cin >> c[i]; }
  dp[0][0] = 0;
  loop(i, m) {
    loop(j, n) {
      if (dp[i][j] == INM)
        continue;
      dp[i + 1][j + 1] = min(dp[i][j] + c[j] * d[i], dp[i + 1][j + 1]);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  }
  int ans = INM;
  loop(i, m) ans = min(ans, dp[i][n]);
  cout << dp[n - 1][m - 1] << endl;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

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

int n, m, an = 1e9;
int d[1002];
int c[1002];
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];
  vector<vector<int>> vec(m + 2, vector<int>(n + 2, 1e9));
  vec[0][0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      vec[i + 1][j] = min(vec[i + 1][j], vec[i][j]);
      vec[i + 1][j + 1] = min(vec[i + 1][j + 1], vec[i][j] + c[i] * d[j]);
    }
  }
  for (int i = 0; i <= m; i++)
    an = min(an, vec[i][n]);
  cout << an << endl;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

int n, m, an = 1e9;
int d[1002];
int c[1002];
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];
  vector<vector<int>> vec(m + 2, vector<int>(n + 1e9));
  vec[0][0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      vec[i + 1][j] = min(vec[i + 1][j], vec[i][j]);
      vec[i + 1][j + 1] = min(vec[i + 1][j + 1], vec[i][j] + c[i] * d[j]);
    }
  }
  for (int i = 0; i <= m; i++)
    an = min(an, vec[i][n]);
  cout << an << endl;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

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

long long int table[1001][1001];

int main() {

  int n, m;

  cin >> n >> m;

  int dir[n], weather[m];

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

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

  n++;
  m++;

  for (int i = 0; i < n; i++) {
    table[0][i] = 10000000000;
  }

  for (int i = 0; i < m; i++) {
    table[i][0] = 0;
  }

  for (int i = 1; i < m; i++) {
    for (int j = 1; j < n; j++) {
      if (m - n + 1 < i && (m - i + j < n)) {
        table[i][j] = 10000000000;
        continue;
      }
      table[i][j] = min(table[i - 1][j],
                        table[i - 1][j - 1] + dir[j - 1] * weather[i - 1]);
    }
  }

  cout << table[m - 1][n - 1] << endl;

  return 0;
}

Error: 0

Fixed submission:

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

long long int table[1000][1000];

int main() {

  int n, m;

  cin >> n >> m;

  int dir[n], weather[m];

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

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

  n++;
  m++;

  for (int i = 0; i < n; i++) {
    table[0][i] = 10000000;
  }

  for (int i = 0; i < m; i++) {
    table[i][0] = 0;
  }

  for (int i = 1; i < m; i++) {
    for (int j = 1; j < n; j++) {
      if (m - n + 1 < i && (m - i + j < n)) {
        table[i][j] = 10000000;
        continue;
      }
      table[i][j] = min(table[i - 1][j],
                        table[i - 1][j - 1] + dir[j - 1] * weather[i - 1]);
    }
  }

  cout << table[m - 1][n - 1] << endl;

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

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

int n, m, an = 1e9;
int d[1000];
int c[1000];
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];
  vector<vector<int>> vec(n + 2, vector<int>(m + 2, 1e9));
  vec[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      vec[i][j + 1] = min(vec[i][j + 1], vec[i][j]);
      vec[i + 1][j + 1] = min(vec[i + 1][j + 1], vec[i][j] + c[j] * d[i]);
    }
  }
  for (int i = 0; i <= m; i++)
    an = min(an, vec[n][i]);
  cout << an << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, m, an = 10000000;
int d[1000];
int c[1000];
void g(int city, int day, int tire) {
  if (day == m && city == n)
    an = min(an, tire);
  if (day < m) {
    g(city, day + 1, tire);
    if (city < n)
      g(city + 1, day + 1, tire + d[city] * c[day]);
  }
}
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];
  g(0, 0, 0);
  cout << an << endl;
}
Problem p00534 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;
static const int INF = 1e9;
int ans = INF;
int dp[1001][1001];

void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> D(N);
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }
  vector<int> C(M);
  for (int i = 0; i < M; ++i) {
    cin >> C[i];
  }
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= M; ++j) {
      dp[i][j] = INF;
    }
  }
  for (int i = 0; i < M; ++i) {
    dp[0][i] = 0;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      dp[i + 1][j + 1] = min(dp[i + 1][j], dp[i][j] + D[i] * C[j]);
    }
  }
  cout << dp[N][M] << endl;
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int ans = 1e9;
vector<int> D;
vector<int> C;
int N, M;

void DFS(int n, int m, int sum) {
  if (n < N && m == M) {
    return;
  }
  if (n == N) {
    ans = min(ans, sum);
    return;
  }
  DFS(n + 1, m + 1, sum + D[n] * C[m]);
  DFS(n, m + 1, sum);
}

void solve() {
  cin >> N >> M;
  D.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }
  C.resize(M);
  for (int i = 0; i < M; ++i) {
    cin >> C[i];
  }
  DFS(0, 0, 0);
  cout << ans << endl;
}

int main() {
  solve();
  return (0);
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

long long int dp[1002][1002]; // dp[?????\\???][???]
const int INF = 1145141919;

int main() {
  int n, m, kyori[1002] = {};
  int tenki[1002] = {};
  long long int ans = INF;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> kyori[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> tenki[j];
  }
  for (int i = 0; i <= 1001; i++) {
    for (int j = 0; j <= 1001; j++) {
      dp[i][j] = INF;
    }
  }
  for (int i = 0; i < m; i++) {
    dp[i][0] = 0;
  }
  for (int i = 1; i <= m; i++) {   //??\\??°
    for (int j = 1; j <= n; j++) { //???
      dp[i][j] =
          min(dp[i - 1][j - 1] + kyori[j - 1] * tenki[i - 1], dp[i - 1][j]);
    }
  }
  cout << dp[m][n] << endl;
  return 0;
}

Error: -11

Fixed submission:

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

long long int dp[1002][1002]; // dp[?????\\???][???]
const int INF = 1145141919;

int main() {
  int n, m, kyori[1002] = {};
  int tenki[1002] = {};
  long long int ans = INF;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> kyori[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> tenki[j];
  }
  for (int i = 0; i <= 1002; i++) {
    for (int j = 0; j <= 1002; j++) {
      dp[i][j] = INF;
    }
  }
  for (int i = 0; i < m; i++) {
    dp[i][0] = 0;
  }
  for (int i = 1; i <= m; i++) {   //??\\??°
    for (int j = 1; j <= n; j++) { //???
      dp[i][j] =
          min(dp[i - 1][j - 1] + kyori[j - 1] * tenki[i - 1], dp[i - 1][j]);
    }
  }
  cout << dp[m][n] << endl;
  return 0;
}
Problem p00534 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
double EPS = 1e-8;
int INF = 2e9;
ll dp[1010][1010];
int main() {
  int m, n;
  int c[1010], d[1010];
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  REP(i, n) cin >> c[i + 1];
  REP(i, m) cin >> d[i + 1];
  dp[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= min(i, n); j++) {
      if (j == 0)
        dp[i][j] = dp[i - 1][j];
      else {
        if (dp[i - 1][j] == -1 && dp[i - 1][j - 1] == -1)
          continue;
        else if (dp[i - 1][j] == -1)
          dp[i][j] = dp[i - 1][j - 1] + c[j] * d[i];
        else if (dp[i - 1][j - 1] == -1)
          dp[i][j] = dp[i - 1][j];
        else
          dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + c[j] * d[i]);
      }
    }
  }
  cout << dp[m][n] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
double EPS = 1e-8;
int INF = 2e9;
ll dp[1000][1000];
int main() {
  int m, n;
  int c[1000], d[1000];
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  REP(i, n) cin >> c[i + 1];
  REP(i, m) cin >> d[i + 1];
  dp[0][0] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= min(i, n); j++) {
      if (j == 0)
        dp[i][j] = dp[i - 1][j];
      else {
        if (dp[i - 1][j] == -1 && dp[i - 1][j - 1] == -1)
          continue;
        else if (dp[i - 1][j] == -1)
          dp[i][j] = dp[i - 1][j - 1] + c[j] * d[i];
        else if (dp[i - 1][j - 1] == -1)
          dp[i][j] = dp[i - 1][j];
        else
          dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + c[j] * d[i]);
      }
    }
  }
  cout << dp[m][n] << endl;
}
Problem p00534 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
unsigned long long dp[1001][1001];
int main() {
  int n, m, d[1001], c[1001];
  cin >> n >> m;
  /*for(int i=0;i<=n+1;i++){
          for(int j=0;j<=m+1;j++){
                  dp[i][j]=0;
          }
  }*/
  memset(dp, 0, sizeof(dp));
  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 < n; i++) {
    for (int j = 1 + i; j <= m; j++) {
      if (dp[i + 1][j + 1] == 0) {
        dp[i + 1][j + 1] += dp[i][j] + c[j] * d[i + 1];
        // cout<<dp[i+1][j+1]<<endl;
      }
      if (dp[i][j] != 0 && dp[i][j] < dp[i][j + 1]) {
        dp[i][j + 1] = dp[i][j];
      }
    }
  }
  unsigned long long minx = 164764153;
  for (int i = m - n + 1; i <= m + 1; i++) {
    // minx=min(dp[n][i],minx);
    if (dp[n][i] < minx && dp[n][i] != 0)
      minx = min(dp[n][i], minx);
  }
  /*for(int i=0;i<n+2;i++){
          for(int j=1;j<=m+1;j++){
                  cout<<dp[i][j]<<" ";
          }
          cout<<endl;
  }*/

  cout << minx << endl;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
int d[1001], c[1001];
int n, m;
int minx = 9999999;
void sugii(int, int, int, int);
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> c[i];
  }
  sugii(1, 0, 1, 1);
  cout << minx << endl;
}
void sugii(int sumnichi, int hirou, int n2, int m2) {
  if (n2 == n + 1) {
    minx = min(minx, hirou);
    // cout<<hirou<<endl;
  }

  if (m2 <= m && n2 <= n) {
    sugii(sumnichi + 1, hirou + (d[n2] * c[m2]), n2 + 1, m2 + 1);
    sugii(sumnichi + 1, hirou, n2, m2 + 1);
  }
}