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

#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char DIRECTION[] = "ESWN";
ll passed[102][102][4];

int main() {
  while (true) {
    ll H, W, L;
    cin >> H >> W >> L;
    if (H == 0 && W == 0 && L == 0) {
      break;
    }
    memset(passed, -1, sizeof(passed));
    vector<string> field(H + 2);
    field[0] = field[H + 1] = string(W + 2, '#');
    int x = 0, y = 0;
    for (int i = 1; i <= H; ++i) {
      string line;
      cin >> line;
      field[i] = "#" + line + "#";
      for (int j = 0; j < field[i].size(); ++j) {
        if (field[i][j] != '.' && field[i][j] != '#') {
          x = j;
          y = i;
        }
      }
    }
    int dir = 0;
    switch (field[y][x]) {
    case 'E':
      dir = 0;
      break;
    case 'S':
      dir = 1;
      break;
    case 'W':
      dir = 2;
      break;
    case 'N':
      dir = 3;
      break;
    }
    for (ll i = 0; i < L; ++i) {
      if (passed[y][x][dir] >= 0) {
        ll duration = i - passed[y][x][dir];
        i = (L - i) / duration * duration + i;
        if (i >= L) {
          i -= duration;
        }
      } else {
        passed[y][x][dir] = i;
      }
      int nx = x + dx[dir], ny = y + dy[dir];
      while (field[ny][nx] == '#') {
        dir = (dir + 1) & 0x03;
        nx = x + dx[dir];
        ny = y + dy[dir];
      }
      x = nx;
      y = ny;
    }
    cout << y << " " << x << " " << DIRECTION[dir] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char DIRECTION[] = "ESWN";

int main() {
  while (true) {
    int H, W, L;
    cin >> H >> W >> L;
    if (H == 0 && W == 0 && L == 0) {
      break;
    }
    vector<string> field(H + 2);
    field[0] = field[H + 1] = string(W + 2, '#');
    int x = 0, y = 0;
    for (int i = 1; i <= H; ++i) {
      string line;
      cin >> line;
      field[i] = "#" + line + "#";
      for (int j = 0; j < field[i].size(); ++j) {
        if (field[i][j] != '.' && field[i][j] != '#') {
          x = j;
          y = i;
        }
      }
    }
    int dir = 0;
    switch (field[y][x]) {
    case 'E':
      dir = 0;
      break;
    case 'S':
      dir = 1;
      break;
    case 'W':
      dir = 2;
      break;
    case 'N':
      dir = 3;
      break;
    }
    while (L--) {
      int nx = x + dx[dir], ny = y + dy[dir];
      while (field[ny][nx] == '#') {
        dir = (dir + 1) & 0x03;
        nx = x + dx[dir];
        ny = y + dy[dir];
      }
      x = nx;
      y = ny;
    }
    cout << y << " " << x << " " << DIRECTION[dir] << endl;
  }
  return 0;
}
Problem p01437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

long long mem[110][110][4];

int main() {
  long long h, w, n;
  string m[110];
  while (true) {
    cin >> h >> w >> n;
    if (h == 0 && w == 0 && n == 0)
      break;
    rep(i, h) cin >> m[i + 1];
    m[0] = m[h + 1] = "";
    rep(i, w) m[0] += "#";
    rep(i, w) m[h + 1] += "#";
    rep(i, h + 2) m[i] = "#" + m[i] + "#";
    h += 2;
    w += 2;
    int x, y, d;
    rep(i, h) rep(j, w) {
      if (m[i][j] == 'E')
        d = 0;
      if (m[i][j] == 'S')
        d = 1;
      if (m[i][j] == 'W')
        d = 2;
      if (m[i][j] == 'N')
        d = 3;
      if (isalpha(m[i][j])) {
        x = j;
        y = i;
      }
    }
    rep(i, 110) rep(j, 110) rep(k, 4) mem[i][j][k] = -1;
    rep(i, n) {
      int xx = x + dx[d], yy = y + dy[d];
      while (m[yy][xx] == '#') {
        d = (d + 1) % 4;
        xx = x + dx[d];
        yy = y + dy[d];
      }
      x = xx;
      y = yy;
      if (mem[y][x][d] != -1) {
        long long k = i - mem[y][x][d];
        long long a = (n - i) / k;
        if (a > 1)
          i += (a - 1) * k;
      } else {
        mem[y][x][d] = i;
      }
    }
    cout << y << " " << x << " "
         << "ESWN"[d] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int mem[110][110][4];

int main() {
  long long h, w, n;
  string m[110];
  while (true) {
    cin >> h >> w >> n;
    if (h == 0 && w == 0 && n == 0)
      break;
    rep(i, h) cin >> m[i + 1];
    m[0] = m[h + 1] = "";
    rep(i, w) m[0] += "#";
    rep(i, w) m[h + 1] += "#";
    rep(i, h + 2) m[i] = "#" + m[i] + "#";
    h += 2;
    w += 2;
    int x, y, d;
    rep(i, h) rep(j, w) {
      if (m[i][j] == 'E')
        d = 0;
      if (m[i][j] == 'S')
        d = 1;
      if (m[i][j] == 'W')
        d = 2;
      if (m[i][j] == 'N')
        d = 3;
      if (isalpha(m[i][j])) {
        x = j;
        y = i;
      }
    }
    rep(i, 110) rep(j, 110) rep(k, 4) mem[i][j][k] = -1;
    rep(i, n) {
      int xx = x + dx[d], yy = y + dy[d];
      while (m[yy][xx] == '#') {
        d = (d + 1) % 4;
        xx = x + dx[d];
        yy = y + dy[d];
      }
      x = xx;
      y = yy;
      if (mem[y][x][d] != -1) {
        int k = i - mem[y][x][d];
        int a = (n - i) / k;
        if (a > 1)
          i += (a - 1) * k;
      } else {
        mem[y][x][d] = i;
      }
    }
    cout << y << " " << x << " "
         << "ESWN"[d] << endl;
  }
  return 0;
}
Problem p01437 (C++) — buggy submission, verdict: Time Limit Exceeded

// 11
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  for (long long h, w, l; cin >> h >> w >> l, h | w | l;) {
    bool s[102][102] = {};
    int x, y, d;
    string ds = "NESW";
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        char c;
        cin >> c;
        s[i][j] = c != '#';
        if (c != '#' && c != '.') {
          x = j;
          y = i;
          d = ds.find(c);
        }
      }
    }
    long long p[102][102][4];
    fill(p[0][0], p[102][0], -1);
    while (l) {
      int dx[] = {0, 1, 0, -1};
      int dy[] = {-1, 0, 1, 0};
      for (;;) {
        if (p[y][x][d] != -1) {
          long long m = p[y][x][d] - l;
          if (l > m) {
            l = l % m + m;
          }
        }
        p[y][x][d] = l;
        if (s[y + dy[d]][x + dx[d]])
          break;
        d = (d + 1) % 4;
      }
      y += dy[d];
      x += dx[d];
      l--;
    }
  end:
    cout << y << ' ' << x << ' ' << ds[d] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// 11
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  for (long long h, w, l; cin >> h >> w >> l, h | w | l;) {
    bool s[102][102] = {};
    int x, y, d;
    string ds = "NESW";
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        char c;
        cin >> c;
        s[i][j] = c != '#';
        if (c != '#' && c != '.') {
          x = j;
          y = i;
          d = ds.find(c);
        }
      }
    }
    long long p[102][102][4];
    fill(p[0][0], p[102][0], -1);
    while (l) {
      int dx[] = {0, 1, 0, -1};
      int dy[] = {-1, 0, 1, 0};
      for (;;) {
        if (p[y][x][d] != -1) {
          int m = p[y][x][d] - l;
          if (l > m) {
            l = l % m + m;
          }
        }
        p[y][x][d] = l;
        if (s[y + dy[d]][x + dx[d]])
          break;
        d = (d + 1) % 4;
      }
      y += dy[d];
      x += dx[d];
      l--;
    }
  end:
    cout << y << ' ' << x << ' ' << ds[d] << endl;
  }
  return 0;
}
Problem p01437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(void) {
  long long int i, l, flag[100][100][4],
      dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}, h, w, d, j, k, x, y;
  char str[100][101], dir[5] = {"NESW"};
  while (1) {
    scanf("%lld%lld%lld%*c", &h, &w, &l);
    if (h == 0 && w == 0 && l == 0)
      break;
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        str[i][j] = getchar();
        if (isupper(str[i][j])) {
          x = j;
          y = i;
          for (k = 0; k < 4; k++)
            if (str[i][j] == dir[k])
              d = k;
          str[i][j] = '.';
        }
      }
      str[i][j] = '\\0';
      getchar();
    }
    memset(flag, -1, sizeof(flag));
    for (i = 0; i < l; i++) {
      if (flag[y][x][d] == -1)
        flag[y][x][d] = i;
      else {
        i += (i - flag[y][x][d]) * ((l - i) / (i - flag[y][x][d])) - 1;
        memset(flag, -1, sizeof(flag));
        continue;
      }
      while (1) {
        if (x + dx[d] >= 0 && x + dx[d] < w && y + dy[d] >= 0 &&
            y + dy[d] < h && str[y + dy[d]][x + dx[d]] == '.') {
          x = x + dx[d];
          y = y + dy[d];
          break;
        }
        d = (d + 1) % 4;
      }
    }
    printf("%lld %lld %c\\n", y + 1, x + 1, dir[d]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(void) {
  int h, w, dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}, flag[100][100][4], i,
            j, k, x, y, d;
  long long int l;
  char str[100][101], dir[5] = {"NEST"};
  while (1) {
    scanf("%d%d%d%*c", &h, &w, &l);
    if (h == 0 && w == 0 && l == 0)
      break;
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        str[i][j] = getchar();
        if (isupper(str[i][j])) {
          x = j;
          y = i;
          for (k = 0; k < 4; k++)
            if (str[i][j] == dir[k])
              d = k;
          str[i][j] = '.';
        }
      }
      getchar();
    }
    memset(flag, -1, sizeof(flag));
    for (i = 0; i < l; i++) {
      if (flag[y][x][d] == -1)
        flag[y][x][d] = i;
      else {
        i += (i - flag[y][x][d]) * (l - i) / (i - flag[y][x][d]) +
             1; // 残りの歩数 % 一周するのにかかる歩数
        memset(flag, -1, sizeof(flag));
      }
      while (1) {
        if (x + dx[d] >= 0 && x + dx[d] < w && y + dy[d] >= 0 &&
            y + dy[d] < h && str[y + dy[d]][x + dx[d]] == '.') {
          x = x + dx[d];
          y = y + dy[d];
          break;
        }
        d = (d + 1) % 4;
      }
    }
    printf("%d %d %c\\n", y + 1, x + 1, dir[d]);
  }
  return 0;
}
Problem p01437 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int H, W;
ll L;
vector<string> maze;
vector<vector<vector<ll>>> vis;

inline bool inrect(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; }

tuple<int, int, char> solve() {
  vis.assign(H, vector<vector<ll>>(W, vector<ll>(4, -1)));
  int x = 0, y = 0, d = 0;
  rep(i, H) rep(j, W) rep(k, 4) if (maze[i][j] == "NESW"[k]) {
    x = i;
    y = j;
    d = k;
    break;
  }
  for (ll step = 0; step <= L; ++step) {
    if (vis[x][y][d] != -1) {
      L = vis[x][y][d] + (L - step) % (step - vis[x][y][d]);
      break;
    }
    vis[x][y][d] = step;
    int nx = x + dx[d], ny = y + dy[d];
    while (!inrect(nx, ny) || maze[nx][ny] == '#') {
      (d += 1) %= 4;
      nx = x + dx[d];
      ny = y + dy[d];
    }
    x = nx;
    y = ny;
  }
  rep(i, H) rep(j, W) rep(k, 4) if (vis[i][j][k] == L) {
    x = i;
    y = j;
    d = k;
    break;
  }
  return make_tuple(x + 1, y + 1, "NESW"[d]);
}

int main() {
  while (cin >> H >> W >> L, H | W | L) {
    maze.assign(H, "");
    rep(i, H) cin >> maze[i];
    int x, y;
    char d;
    tie(x, y, d) = solve();
    cout << x << ' ' << y << ' ' << d << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int H, W, L;
vector<string> maze;
vector<vector<vector<int>>> vis;

inline bool inrect(int x, int y) { return 0 <= x && x < H && 0 <= y && y < W; }

tuple<int, int, char> solve() {
  vis.assign(H, vector<vector<int>>(W, vector<int>(4, -1)));
  int x = 0, y = 0, d = 0;
  rep(i, H) rep(j, W) rep(k, 4) if (maze[i][j] == "NESW"[k]) {
    x = i;
    y = j;
    d = k;
    break;
  }
  int T = min(L, H * W * 4);
  for (int step = 0; step <= T;) {
    if (vis[x][y][d] != -1) {
      L = vis[x][y][d] + (L - step) % (step - vis[x][y][d]);
      break;
    }
    vis[x][y][d] = step;
    int nx = x + dx[d], ny = y + dy[d];
    if (!inrect(nx, ny) || maze[nx][ny] == '#')
      (d += 1) %= 4;
    else
      x = nx, y = ny, step++;
  }
  // FIX LINE (this can't be accepted)
  rep(i, H) rep(j, W) rep(k, 4) if (vis[i][j][k] == L) return make_tuple(
      i + 1, j + 1, "NESW"[k]);
  return make_tuple(-1, -1, '?');
}

int main() {
  while (cin >> H >> W >> L, H | W | L) {
    maze.assign(H, "");
    rep(i, H) cin >> maze[i];
    int x, y;
    char d;
    tie(x, y, d) = solve();
    cout << x << ' ' << y << ' ' << d << '\\n';
  }
  return 0;
}
Problem p01438 (C++) — buggy submission, verdict: Memory Limit Exceeded


#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;

LL dp[1 << 16], ndp[1 << 16];

struct guy {
  LL cost;
  bitset<16> sch;
};

int main(void) {
  for (;;) {
    int n;
    cin >> n;
    if (!n)
      break;
    memset(dp, 0, sizeof(dp));
    vector<guy> dat;
    for (int i = 0; i < n; ++i) {
      LL m, l;
      cin >> m >> l;
      bitset<16> sch;
      for (int j = 0; j < m; ++j) {
        int s, e;
        cin >> s >> e;
        s -= 6;
        e -= 6;
        for (int t = s; t < e; ++t) {
          sch.set(t);
        }
      }
      dat.push_back({l, sch});
    }
    for (int i = 0; i < n; ++i) {
      memset(ndp, 0, sizeof(ndp));
      for (unsigned long nes = 0; nes < (1 << 16); ++nes) {
        ndp[nes] = dp[nes];
        if ((nes & dat[i].sch.to_ulong()) == dat[i].sch.to_ulong()) {
          unsigned long las = nes ^ dat[i].sch.to_ulong();
          ndp[nes] = max(ndp[nes], dp[las] + dat[i].cost);
        }
      }
      for (int j = 0; j < (1 << 16); ++j) {
        dp[j] = ndp[j];
      }
    }
    cout << dp[(1 << 16) - 1] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:


#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;

LL dp[123][1 << 16];

struct guy {
  LL cost;
  bitset<16> sch;
};

int main(void) {
  for (;;) {
    int n;
    cin >> n;
    if (!n)
      break;
    memset(dp, 0, sizeof(dp));
    vector<guy> dat;
    for (int i = 0; i < n; ++i) {
      LL m, l;
      cin >> m >> l;
      bitset<16> sch;
      for (int j = 0; j < m; ++j) {
        int s, e;
        cin >> s >> e;
        s -= 6;
        e -= 6;
        for (int t = s; t < e; ++t) {
          sch.set(t);
        }
      }
      dat.push_back({l, sch});
    }
    for (int i = 0; i < n; ++i) {
      for (unsigned long nes = 0; nes < (1 << 16); ++nes) {
        dp[i + 1][nes] = dp[i][nes];
        if (nes & dat[i].sch == dat[i].sch) {
          unsigned long las = nes ^ dat[i].sch.to_ulong();
          dp[i + 1][nes] = max(dp[i + 1][nes], dp[i][las] + dat[i].cost);
        }
      }
    }
    cout << dp[n][(1 << 16) - 1] << endl;
  }
  return 0;
}
Problem p01438 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int dp[200][1 << 16], mask[200];
int l[200];
int main() {
  int n;
  while (scanf("%d", &n), n) {
    memset(dp, 0, sizeof(dp));
    memset(mask, 0, sizeof(mask));
    rep(i, n) {
      int m;
      scanf("%d%d", &m, &l[i]);
      rep(k, m) {
        int s, e;
        scanf("%d%d", &s, &e);
        s -= 6;
        e -= 6;
        for (int j = s; j < e; j++)
          mask[i] |= 1 << j;
      }
    }
    rep(i, n) rep(j, 1 << 16) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (!(j & mask[i]))
        dp[i + 1][j | mask[i]] = max(dp[i + 1][j | mask[i]], dp[i][j] + l[i]);
    }
    int Max = 0;
    rep(i, 1 << 16) { Max = max(Max, dp[n][i]); }
    printf("%d\\n", Max);
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll dp[200][1 << 16], mask[200];
ll l[200];
int main() {
  int n;
  while (scanf("%d", &n), n) {
    memset(dp, 0, sizeof(dp));
    memset(mask, 0, sizeof(mask));
    rep(i, n) {
      int m;
      scanf("%d%lld", &m, &l[i]);
      rep(k, m) {
        int s, e;
        scanf("%d%d", &s, &e);
        s -= 6;
        e -= 6;
        for (int j = s; j < e; j++)
          mask[i] |= 1 << j;
      }
    }
    rep(i, n) rep(j, 1 << 16) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (!(j & mask[i]))
        dp[i + 1][j | mask[i]] = max(dp[i + 1][j | mask[i]], dp[i][j] + l[i]);
    }
    ll Max = 0;
    rep(i, 1 << 16) { Max = max(Max, dp[n][i]); }
    printf("%lld\\n", Max);
  }
}
Problem p01438 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  int n;
  while (cin >> n && n) {
    vector<VL> dp(n + 1, VL(1 << 16));
    REP(i, n) {
      int m, x = 0;
      ll l;
      cin >> m >> l;
      while (m--) {
        int s, e;
        cin >> s >> e;
        s -= 6;
        e -= 6;
        FOR(j, s, e - 1) x += 1 << j;
      }
      REP(j, 1 << 16) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        if ((j & x) > 0)
          continue;
        dp[i + 1][j | x] = max(dp[i + 1][j | x], dp[i][j] + l);
      }
    }
    ll ans = 0;
    REP(j, 1 << 16) ans = max(ans, dp[n][j]);
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  int n;
  while (cin >> n && n) {
    vector<VL> dp(n + 1, VL(1 << 17));
    REP(i, n) {
      int m;
      ll l;
      cin >> m >> l;
      int x = 0;
      while (m--) {
        int s, e;
        cin >> s >> e;
        s -= 6;
        e -= 6;
        FOR(k, s, e - 1) x += 1 << k;
      }
      REP(j, 1 << 17) {
        if ((j & x) > 0)
          continue;
        dp[i + 1][j | x] = max(dp[i + 1][j | x], dp[i][j] + l);
      }
    }
    ll ans = 0;
    REP(j, 1 << 17) ans = max(ans, dp[n][j]);
    cout << ans << endl;
  }
  return 0;
}
Problem p01438 (C++) — buggy submission, verdict: Runtime Error

#include <assert.h>
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int dp[2][(1 << 16)] = {0};
    // memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;

    rep(i, n) {
      int m, l;
      int s, e;
      int mask = 0;

      cin >> m >> l;
      rep(j, m) {
        cin >> s >> e;
        s -= 6;
        e -= 6;
        for (int k = s; k < e; k++) {
          mask |= (1 << k);
        }
      }
      rep(j, (1 << 16)) {
        if (dp[i % 2][j] == -1)
          continue;
        if (j & mask)
          continue;
        dp[(i + 1) % 2][j | mask] =
            max(dp[(i + 1) % 2][j | mask], dp[i % 2][j] + l);
      }
      memcpy(dp[i % 2], dp[(i + 1) % 2], sizeof(dp[i % 2]));
    }
    int ans = 0;
    rep(i, (1 << 16)) { ans = max(ans, dp[n % 2][i]); }
    cout << ans << endl;
  }
}

Error: -6
f5666496-40db-4a5b-ae00-8f5edb68a483.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p01438/C++/s846432980.cpp:48: int main(): Assertion `j + temp <= (1 << 16)' failed.


Fixed submission:

#include <assert.h>
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

bool timeCheck(int d[100][16][2], int i, int j, int k, int &ret) {
  for (int l = d[i][k][0]; l < d[i][k][1]; l++) {
    int temp = 15 - l;
    if ((j >> temp & 1) == 1)
      return 0;
    ret += 1 << temp;
  }
  return 1;
}

int main() {
  int n;
  while (cin >> n, n) {
    int m[100], l[100];
    int d[100][16][2] = {0};
    rep(i, n) {

      cin >> m[i] >> l[i];
      rep(j, m[i]) {
        cin >> d[i][j][0] >> d[i][j][1];
        d[i][j][0] -= 6;
        d[i][j][1] -= 6;
      }
    }

    long long dp[2][(1 << 16) + 1] = {0};
    rep(i, n) {
      rep(j, (1 << 16) + 1) {
        rep(k, m[i]) {
          // cout << i << ' ' << j << ' ' << k << endl;
          int temp = 0;
          if (timeCheck(d, i, j, k, temp)) {
            // debug(temp)
            /*
            int ret = j; rep(l,18){ cout << ret % 2; ret/=2; }
            cout << endl;;
            ret = j + temp; rep(l,18){ cout << ret % 2; ret/=2; }
            cout << endl;;
            */
            assert(j + temp <= (1 << 16));
            dp[(i + 1) % 2][j + temp] =
                max(dp[(i + 1) % 2][j + temp], dp[i % 2][j] + l[i]);
            dp[i % 2][j] = 0;
          }
        }
      }
    }
    long long ans = 0;
    rep(i, (1 << 16)) { ans = max(ans, dp[n % 2][i]); }
    cout << ans << endl;
  }
}