alexjercan/bugnet huggingface dataset:
Problem p00497 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
  if (a < b)
    a = b;
}
template <class T, class C> void chmin(T &a, C b) {
  if (b < a)
    a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }

int v[5048][5048];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);

  rep(i, m) {
    int x, y, l;

    cin >> y >> x >> l;

    chmax(v[y][x], l + 1);
  }

  int res = 0;
  REP(y, 1, n + 1) REP(x, 1, y + 1) {
    chmax(v[y][x], max(v[y - 1][x] - 1, v[y - 1][x - 1] - 1));

    res += 0 < v[y][x];
  }

  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
  if (a < b)
    a = b;
}
template <class T, class C> void chmin(T &a, C b) {
  if (b < a)
    a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }

int main() {
  bitset<12502500> bit;

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

  int x, y, l, tmp;
  while (m--) {
    scanf("%d %d %d", &y, &x, &l);
    tmp = x;

    rep(i, l + 1) {
      rep(j, i + 1) {
        bit[y * (y - 1) / 2 + x - 1] = true;

        x++;
      }

      x = tmp;
      y++;
    }
  }

  printf("%d\\n", bit.count());
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 5010

int main() {
  vector<int> nails[SIZE + 3];
  int n, m, a, b, x, ans = 0;

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

  for (int i = 0; i <= n + 2; i++) {
    nails[i].resize(i + 5, 0);
  }

  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &x);

    nails[a][b]++;
    nails[a][b + 1]--;
    nails[a + x + 1][b]--;
    nails[a + x + 2][b + 1]++;
    nails[a + x + 1][b + x + 2]++;
    nails[a + x + 2][b + x + 2]--;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      nails[i][j + 1] += nails[i][j];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      nails[i + 1][j] += nails[i][j];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      nails[i + 1][j + 1] += nails[i][j];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (nails[i][j] > 0)
        ans++;
    }
  }

  printf("%d\\n", ans);

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 5010

int nails[SIZE][SIZE] = {0};

int main() {
  int n, m, a, b, x, ans = 0;

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

  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &x);

    nails[a][b]++;
    nails[a][b + 1]--;
    nails[a + x + 1][b]--;
    nails[a + x + 2][b + 1]++;
    nails[a + x + 1][b + x + 2]++;
    nails[a + x + 2][b + x + 2]--;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      nails[i][j + 1] += nails[i][j];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      nails[i + 1][j] += nails[i][j];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      nails[i + 1][j + 1] += nails[i][j];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (nails[i][j] > 0)
        ans++;
    }
  }

  printf("%d\\n", ans);

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

#include <iostream>
using namespace std;

short max(short x, short y) {
  if (x < y)
    return y;
  return x;
}

int main() {
  static short imos[5005][5005] = {0};
  int n, m, a, b, x;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &a, &b, &x);
    imos[a][b] = max(imos[a][b], x + 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++) {
      imos[i][j] =
          max(imos[i][j], max(imos[i - 1][j] - 1, imos[i - 1][j - 1] - 1));
      if (imos[i][j] > 0)
        ans++;
    }
  printf("%d\\n", ans);
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
unsigned short n, m, a, b, x;
const unsigned short N = 6011;
unsigned short imos[N + 1][N + 1] = {0};

int main() {
  scanf("%hd%hd", &n, &m);
  // for(unsigned short i=1;i<=n;i++)for(unsigned short
  // j=1;j<=i;j++){imos[i][j]=-20000; imos[N-i][N-j]=20000;}
  for (unsigned short i = 0; i < m; i++) {
    scanf("%hd%hd%hd", &a, &b, &x);
    imos[a][b]++;
    imos[a + x + 1][b]--;
    imos[N - a][N - (b + 1)]--;
    // imos1[a][b+2]++;
    imos[N - (a + x + 1)][N - (b + x + 2)]++;
    // imos1[a+x+1][b+x+3]--;
  }
  for (unsigned short i = 1; i <= n; i++)
    for (unsigned short j = 1; j <= i; j++)
      imos[i][j] += imos[i - 1][j];
  for (unsigned short i = 1; i <= n; i++)
    for (unsigned short j = 1; j <= i; j++)
      imos[i][j] += imos[i][j - 1];
  // for(int i=1;i<=n;i++)for(int j=1;j<=i;j++)imos[i][j]-=20000;
  for (unsigned short i = 1; i <= n; i++)
    for (unsigned short j = 1; j <= i; j++)
      imos[N - i][N - j] += imos[N - (i - 1)][N - (j - 1)];
  for (unsigned short i = 1; i <= n; i++)
    for (unsigned short j = 1; j <= i; j++)
      imos[N - i][N - j] += imos[N - i][N - (j - 1)];
  // for(int i=1;i<=n;i++)for(int j=1;j<=i;j++)imos[N-i][N-j]+=20000;
  int ans = 0;
  for (unsigned short i = 1; i <= n; i++)
    for (unsigned short j = 1; j <= i; j++) {
      unsigned short s = imos[i][j] + imos[N - i][N - j];
      if (s != 0)
        ans++;
    }
  printf("%d\\n", ans);
}
Problem p00497 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N, M;
int d[5010][5010];
int h[5010][5010];
int t[5010][5010];

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    a--;
    b--;
    d[a][b] += 1;
    d[a][b + 1] -= 1;
    d[a + x + 1][b] -= 1;
    d[a + x + 2][b + 1] += 1;
    d[a + x + 1][b + x + 2] += 1;
    d[a + x + 2][b + x + 1 + 1] -= 1;
  }

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      h[i][j] = ((i > 0 && j > 0) ? h[i - 1][j - 1] : 0) + d[i][j];
    }
  }

  for (int i = 0; i <= N; i++) {
    int g = 0;
    for (int j = 0; j <= N; j++) {
      g += h[j][i];
      t[j][i] = g;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int g = 0;
    for (int j = 0; j <= i; j++) {
      g += t[i][j];
      if (g > 0)
        ans++;
    }
  }
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

int N, M;
int d[5010][5010];

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    a--;
    b--;
    for (int y = a; y <= a + x; y++) {
      d[y][b] += 1;
      d[y][b + y - a + 1] -= 1;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int g = 0;
    for (int j = 0; j <= i; j++) {
      g += d[i][j];
      if (g > 0)
        ans++;
    }
  }
  cout << ans << "\\n";
  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int index(int y, int x) { return y * (y + 1) / 2 + x; }

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> nail(index(N, N));
  for (int i = 0; i < M; ++i) {
    int A, B, X;
    cin >> A >> B >> X;
    --A;
    --B;
    nail[index(A, B)] = max(nail[index(A, B)], X + 1);
  }

  int answer = 0;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= i; ++j) {
      if (0 <= j - 1)
        nail[index(i, j)] =
            max(nail[index(i, j)], nail[index(i - 1, j - 1)] - 1);
      if (j < i)
        nail[index(i, j)] = max(nail[index(i, j)], nail[index(i - 1, j)] - 1);
      if (nail[index(i, j)])
        ++answer;
    }
  cout << answer << endl;
}

Error: MLE

Fixed submission:

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

// for debug
void print(const vector<vector<int>> &nail) {
  for (auto n : nail) {
    for (auto i : n)
      cout << " " << i;
    cout << endl;
  }
}

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> nail(N + 3, vector<int>(N + 3, 0));
  for (int i = 0; i < M; ++i) {
    int A, B, X;
    cin >> A >> B >> X;
    ++nail[A][B];
    --nail[A][B + 1];
    --nail[A + X + 1][B];
    ++nail[A + X + 1][B + X + 2];
    ++nail[A + X + 2][B + 1];
    --nail[A + X + 2][B + X + 2];
  }

  // 横
  for (int i = 1; i <= N + 2; ++i)
    for (int j = 1; j <= N + 2; ++j)
      nail[i][j] += nail[i][j - 1];
  // 縦
  for (int j = 1; j <= N + 2; ++j)
    for (int i = 1; i <= N + 2; ++i)
      nail[i][j] += nail[i - 1][j];
  // 斜め
  for (int i = 1; i <= N + 2; ++i)
    for (int t = 1; i + t <= N + 2; ++t)
      nail[i + t][1 + t] += nail[i + t - 1][1 + t - 1];

  int answer = 0;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      if (nail[i][j])
        ++answer;
  cout << answer << endl;
}
Problem p00497 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

constexpr long long int MOD = 1000000007;
// const int MOD = 1000000007;
// constexpr int MOD = 998244353;
// constexpr long long int MOD = 998244353;

// const double EPS = 1e-8;

int N, M, K, H, W, L, R;
// long long int N, M, K, H, W, L, R;

int v[5001][5001];
int sum[5001][5002];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> K >> N;
  for (int i = 0; i < N; i++) {
    cin >> H >> W >> M;
    v[H + M][W] = max(v[H + M][W], M + 1);
  }
  for (int i = 5000; i >= 1; i--) {
    for (int j = 4999; j >= i; j--) {
      v[j][i] = max(v[j][i], v[j + 1][i] - 1);
    }
  }
  for (int i = 1; i <= 5000; i++) {
    for (int j = 1; j <= i; j++) {
      sum[i][j]++;
      sum[i][j + v[i][j]]--;
    }
  }
  for (int i = 1; i <= 5000; i++) {
    for (int j = 2; j <= i; j++)
      sum[i][j] += sum[i][j - 1];
  }
  int ans = 0;
  for (int i = 1; i <= 5000; i++) {
    for (int j = 1; j <= i; j++)
      ans += !!sum[i][j];
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include "algorithm"
#include "climits"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "set"
#include "stack"
#include "string"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;
int num[5005][5005];

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);

  scanf("%lld %lld", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%lld %lld %lld", &H, &W, &K);
    for (int j = 0; j <= K; j++) {
      num[H + j][W]++;
      num[H + j][W + 1 + j]--;
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= i; j++) {
      num[i][j] += num[i][j - 1];
      if (num[i][j] > 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstdio>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n, m;
vector<int> cell[5010];

int main() {
  rep(i, 5010) { rep(j, i + 1) cell[i].push_back(0); }
  scanf("%d%d", &n, &m);
  rep(i, m) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    a--;
    b--;
    cell[a][b] += 1;
    if (a >= b + 1)
      cell[a][b + 1] += -1;
    cell[a + x + 1][b] += -1;
    cell[a + x + 2][b + 1] += 1;
    if (a + x + 1 >= b + x + 2)
      cell[a + x + 1][b + x + 2] += 1;
    if (a + x + 2 >= b + x + 2)
      cell[a + x + 2][b + x + 2] += -1;
  }
  rep(i, 5010) for (int j = 1; j < 5010; j++) {
    if (i < j || i < j - 1)
      continue;
    cell[i][j] += cell[i][j - 1];
  }
  rep(i, 5010) for (int j = 1; j < 5010; j++) {
    if (j < i || j - 1 < i)
      continue;
    cell[j][i] += cell[j - 1][i];
  }
  for (int i = 1; i < 5010; i++)
    for (int j = 1; j < 5010; j++) {
      if (i + j > 5010)
        break;
      if (i + j - 1 < j || i + j - 1 < j - 1)
        continue;
      cell[i + j - 1][j] += cell[i + j - 2][j - 1];
    }
  int ans = 0;
  rep(i, 5010) rep(j, 5010) {
    if (i < j)
      continue;
    ans += (cell[i][j] != 0);
  }
  printf("%d\\n", ans);
}

Error: MLE

Fixed submission:

#include <cstdio>
#define rep(i, n) for (int i = 0; i < n; i++)

int n, m;
int cell[5010][5010];

int main() {
  scanf("%d%d", &n, &m);
  rep(i, m) {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    a--;
    b--;
    cell[a][b] += 1;
    cell[a][b + 1] += -1;
    cell[a + x + 1][b] += -1;
    cell[a + x + 2][b + 1] += 1;
    cell[a + x + 1][b + x + 2] += 1;
    cell[a + x + 2][b + x + 2] += -1;
  }
  rep(i, 5010) for (int j = 1; j < 5010; j++) cell[i][j] += cell[i][j - 1];
  rep(i, 5010) for (int j = 1; j < 5010; j++) cell[j][i] += cell[j - 1][i];
  for (int i = 1; i < 5010; i++)
    for (int j = 1; j < 5010; j++) {
      if (i + j > 5010)
        break;
      cell[i + j - 1][j] += cell[i + j - 2][j - 1];
    }
  int ans = 0;
  rep(i, 5010) rep(j, 5010) ans += (cell[i][j] != 0);
  printf("%d\\n", ans);
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

// int tri[5010][5010];
vector<int> tri[5010];
int main() {
  for (int i = 0; i < 5010; i++) {
    tri[i].reserve(i + 1);
    for (int j = 0; j <= i; j++) {
      tri[i][j] = 0;
    }
  }

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

  for (int i = 0; i < m; i++) {
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    a++;

    tri[a][b]++;
    tri[a][b + 1]--;
    tri[a + x + 1][b]--;
    tri[a + x + 2][b + 1]++;
    tri[a + x + 1][b + x + 2]++;
    tri[a + x + 2][b + x + 2]--;
  }

  for (int i = 0; i <= n + 3; i++) {
    for (int j = 0; j <= i; j++) {
      // printf("%d ", tri[i][j]);
    }
    // puts("");
  }

  for (int i = 0; i <= n + 3; i++) {
    for (int j = 1; j <= i; j++) {
      tri[i][j] += tri[i][j - 1];
    }
  }
  for (int i = 1; i <= n + 3; i++) {
    for (int j = 1; j <= i - 1; j++) {
      tri[i][j] += tri[i - 1][j];
    }
  }
  for (int i = 1; i <= n + 3; i++) {
    for (int j = 1; j <= i; j++) {
      tri[i][j] += tri[i - 1][j - 1];
    }
  }

  int cnt = 0;
  for (int i = 2; i <= n + 1; i++) {
    for (int j = 1; j <= i - 1; j++) {
      cnt += !!tri[i][j];
      // printf("%d ", tri[i][j]);
    }
    // puts("");
  }
  printf("%d\\n", cnt);

  return 0;
}

Error: MLE

Fixed submission:

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

int tri[5010][5010];

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

  for (int i = 0; i < m; i++) {
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    a++;

    tri[a][b]++;
    tri[a][b + 1]--;
    tri[a + x + 1][b]--;
    tri[a + x + 2][b + 1]++;
    tri[a + x + 1][b + x + 2]++;
    tri[a + x + 2][b + x + 2]--;
  }

  for (int i = 0; i <= n + 3; i++) {
    for (int j = 0; j <= i; j++) {
      // printf("%d ", tri[i][j]);
    }
    // puts("");
  }

  for (int i = 0; i <= n + 3; i++) {
    for (int j = 1; j <= i; j++) {
      tri[i][j] += tri[i][j - 1];
    }
  }
  for (int i = 1; i <= n + 3; i++) {
    for (int j = 1; j <= i - 1; j++) {
      tri[i][j] += tri[i - 1][j];
    }
  }
  for (int i = 1; i <= n + 3; i++) {
    for (int j = 1; j <= i; j++) {
      tri[i][j] += tri[i - 1][j - 1];
    }
  }

  int cnt = 0;
  for (int i = 2; i <= n + 1; i++) {
    for (int j = 1; j <= i - 1; j++) {
      cnt += !!tri[i][j];
      // printf("%hd ", tri[i][j]);
    }
    // puts("");
  }
  printf("%d\\n", cnt);
}
Problem p00497 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

// int nail[5004][5004]={};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> nail[N + 5];
  for (int i = 0; i < N + 5; ++i)
    nail[i].resize(i + 5);
  for (int i = 0; i < M; ++i) {
    int a, b, x;
    cin >> a >> b >> x;
    ++a;
    ++b;
    --nail[a + x - 1][b - 1];
    ++nail[a + x][b];
    --nail[a + x][b + x + 1];
    ++nail[a + x - 1][b + x + 1];
    ++nail[a - 2][b - 1];
    --nail[a - 2][b];
  }
  for (int x = N + 2; x >= 0; --x) {
    for (int y = nail[x].size() - 1; y >= 0; --y) {
      nail[x][y] += nail[x + 1][y + 1];
    }
  }
  for (int x = N + 2; x >= 0; --x) {
    for (int y = 0; y <= nail[x].size() - 1; ++y) {
      nail[x][y] += nail[x + 1][y];
    }
  }
  long long int ans = 0;
  for (int x = 0; x <= N + 2; ++x) {
    for (int y = 1; y <= nail[x].size() - 1; ++y) {
      nail[x][y] += nail[x][y - 1];
      if (nail[x][y] >= 1)
        ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

int nail[5004][5004] = {};

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int a, b, x;
    cin >> a >> b >> x;
    ++a, ++b;
    nail[a + x - 1][b - 1] -= 1;
    nail[a + x][b] += 1;
    nail[a + x][b + x + 1] -= 1;
    nail[a + x - 1][b + x + 1] += 1;
    nail[a - 2][b - 1] += 1;
    nail[a - 2][b] -= 1;
  }
  for (int x = N + 2; x >= 0; --x) {
    for (int y = N + 2; y >= 0; --y) {
      nail[x][y] += nail[x + 1][y + 1];
    }
  }
  for (int y = 0; y <= N + 2; ++y) {
    for (int x = N + 2; x >= 0; --x) {
      nail[x][y] += nail[x + 1][y];
    }
  }
  int ans = 0;
  for (int x = 0; x <= N + 2; ++x) {
    for (int y = 0; y <= N + 2; ++y) {
      nail[x][y] += nail[x][y - 1];
      if (nail[x][y] >= 1)
        ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00497 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

unsigned short dp[5011][5011];

int main() {

  int n, m;

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    dp[a][b] = c + 1;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (dp[i][j]) {
        dp[i + 1][j] = max<unsigned short>(dp[i + 1][j], dp[i][j] - 1);
        dp[i + 1][j + 1] = max<unsigned short>(dp[i + 1][j + 1], dp[i][j] - 1);
      }
    }
  }
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (dp[i][j])
        sum++;
    }
  }
  cout << sum << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

int **dp;

int main() {

  int n, m;

  dp = (int **)malloc(sizeof(int *) * 5011);
  for (int i = 1; i < 5011; i++)
    *(dp + i) = (int *)malloc(sizeof(int) * (i + 1));

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

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    dp[a][b] = c + 1;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (dp[i][j]) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - 1);
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] - 1);
      }
    }
  }
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (dp[i][j])
        sum++;
    }
  }
  cout << sum << endl;
}