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

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int cubert(int y) {
  double low, mid, high;
  low = 0;
  high = y;
  mid = (high + low) / 2;
  for (int i = 0; i < 32; i++) {
    if (mid * mid * mid > y) {
      high = mid;
    } else
      low = mid;
    mid = (high + low) / 2;
  }
  return (int)mid;
}

int main() {

  int n;
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    int res = INF;
    int m = 0;
    REP(x, n) {
      int y = cubert((int)(n * n * n - x * x * x));
      for (int i = y - 1; i < y + 2; i++) {
        if (n * n * n - x * x * x - i * i * i > 0)
          res = min(res, n * n * n - x * x * x - i * i * i);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int main() {

  int n;
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    int res = INF;
    FOR(x, 1, n) {
      FOR(y, 1, n) {
        if (pow(x, 3) + pow(y, 3) <= pow(n, 3))
          res = min((int)(pow(n, 3) - pow(x, 3) - pow(y, 3)), res);
        else
          break;
      }
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>

using namespace std;

int main() {

  long long int Z, left, right, m, z_3, limit, pow3_Table[1111], maximum,
      tmp_max, tmp;

  for (int i = 1; i <= 1110; i++) {
    pow3_Table[i] = pow(i, 3);
  }

  while (true) {
    scanf("%lld", &Z);
    if (Z == 0)
      break;

    z_3 = pow(Z, 3);

    maximum = -1;
    for (int i = 1; i <= Z - 1; i++) {
      limit = z_3 - pow(i, 3);

      left = 1, right = Z - 1;
      m = (left + right) / 2;
      tmp_max = -1;

      while (left <= right) {
        if (pow3_Table[m] <= limit) {
          tmp_max = max(tmp_max, m);
          left = m + 1;
        } else {
          right = m - 1;
        }
        m = (left + right) / 2;
      }

      tmp = pow(i, 3) + pow3_Table[tmp_max];
      maximum = max(maximum, tmp);
    }

    printf("%lld\\n", z_3 - maximum);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>

using namespace std;

int main() {

  long long int Z, maximum, tmp, limit;

  while (true) {
    scanf("%lld", &Z);
    if (Z == 0)
      break;

    maximum = -1;

    limit = pow(Z, 3);

    for (int i = 1; i <= Z - 1; i++) {
      for (int k = i; k <= Z - 1; k++) {
        tmp = pow(i, 3) + pow(k, 3);
        if (tmp > limit)
          break;

        maximum = max(maximum, tmp);
      }
    }

    printf("%lld\\n", limit - maximum);
  }

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

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

int main() {
  int z, ans;
  while (cin >> z && z != 0) {
    z = z * z * z;
    ans = 0;
    for (int x = 1; x * x * x < z; x++) {
      int y3 = z - x * x * x;
      int y = pow(y3, 1.0 / 3);
      ans = max(ans, y * y * y + x * x * x);
    }
    cout << z - ans << endl;
  };
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int z, ans;
  map<pair<int, int>, int> mymap;
  for (int i = 1; i < 1111; i++)
    for (int j = i; j < 1111; j++)
      mymap.insert(pair<pair<int, int>, int>(pair<int, int>(i, j),
                                             i * i * i + j * j * j));

  while (cin >> z && z != 0) {
    z = z * z * z;
    ans = 0;
    for (int i = 1; i * i * i < z; i++)
      for (int j = i; j * j * j < z; j++) {
        if (mymap[pair<int, int>(i, j)] < z)
          ans = max(mymap[pair<int, int>(i, j)], ans);
        else
          break;
      }
    cout << z - ans << endl;
  };
  return 0;
}
Problem p00691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int z;

  while (cin >> z, z) {
    int max_xy = 0;
    int z3 = z * z * z;

    for (int x = 1; x * x * x <= z3; ++x) {
      int x3 = x * x * x;
      for (int y = 1; y * y * y <= z3 - x3; ++y)
        max_xy = max(max_xy, x3 + y * y * y);
    }

    cout << z3 - max_xy << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int z;

  while (cin >> z, z) {
    int max_xy = 0;
    int z3 = z * z * z;

    for (int x = 1; x <= z3; ++x) {
      for (int y = x; y <= z3; ++y) {
        if (x * x * x + y * y * y <= z3)
          max_xy = max(max_xy, x * x * x + y * y * y);
        else
          break;
      }
    }

    cout << z3 - max_xy << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int z;
    cin >> z;
    if (z == 0) {
      break;
    }
    int x = 1, y = z - 1, z3 = z * z * z, max = 0;
    while (x <= y) {
      int x3 = x * x * x, y3 = y * y * y;
      if (x3 + y3 > z3) {
        y--;
      } else {
        if (max < x3 + y3) {
          max = x3 + y3;
        }
        x++;
      }
    }
    cout << z3 - max << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int z;
    cin >> z;
    if (z == 0) {
      break;
    }
    int z3 = pow(z, 3), max = 0;
    for (int x = 1;; x++) {
      int x3 = pow(x, 3);
      if (2 * x3 > z3) {
        break;
      }
      for (int y = x;; y++) {
        int y3 = pow(y, 3);
        if (x3 + y3 > z3) {
          break;
        }
        if (max < x3 + y3) {
          max = x3 + y3;
        }
      }
    }
    cout << z3 - max << endl;
  }
}
Problem p00691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int n;
  while (cin >> n, n) {
    long long int ans = 100000;
    for (long long int i = 1; i * i * i <= n * n * n; i++) {
      for (long long int j = 1; i * i * i + j * j * j <= n * n * n; j++) {
        ans = min(ans, n * n * n - i * i * i - j * j * j);
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  long long int n;
  while (cin >> n, n) {
    long long int ans = 100000;
    for (long long int i = 1; pow(i, 3) <= pow(n, 3); i++) {
      for (long long int j = 1; pow(i, 3) + pow(j, 3) <= pow(n, 3); j++) {
        long long int m = pow(n, 3) - pow(i, 3) - pow(j, 3);
        ans = min(ans, m);
      }
    }
    cout << ans << endl;
  }
}
Problem p00691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (1) {
    int z, ans = 0;
    cin >> z;
    if (z == 0)
      break;
    for (int x = 1; x < z; x++) {
      for (int y = 1; y < z; y++) {
        if (x * x * x + y * y * y >= z * z * z)
          break;
        ans = max(ans, x * x * x + y * y * y);
      }
    }
    cout << z * z * z - ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int z, ans = 0;
    cin >> z;
    for (int x = 1; x < z; x++) {
      for (int y = 1; y < z; y++) {
        if (x * x * x + y * y * y >= z * z * z)
          break;
        ans = x * x * x + y * y * y;
      }
    }
    cout << z * z * z - ans << endl;
  }
}
Problem p00691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
  int x, y, z, a, t;
  while (cin >> z && z) {
    a = t = pow(z, 3);
    for (x = 1; x < z; x++) {
      for (y = x; y < z; y++) {
        int u;
        u = a - x * x * x - y * y * y;
        if (u > 0 && t > u)
          t = u;
        if (u <= 0)
          break;
      }
    }
    cout << t << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
  int x, y, z, t;
  while (cin >> z && z) {
    t = pow(z, 3);
    for (x = 1; x < z; x++) {
      for (y = x; y < z; y++) {
        int u;
        u = (int)pow(z, 3) - (int)pow(x, 3) - (int)pow(y, 3);
        if (u > 0 && t > u)
          t = u;
      }
    }
    cout << t << endl;
  }
  return 0;
}
Problem p00692 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
bool check(int n, int m, int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}

bool dp[1 << 20];
int main() {
  int T, n = 5, m = 4;
  cin >> T;
  while (T--) {
    int d[20];
    for (int i = 0; i < 20; i++)
      cin >> d[i];
    memset(dp, 0, sizeof(dp));
    dp[(1 << 20) - 1] = 1;
    int ans = 1 << 29;
    for (int t = (1 << 20) - 1; t >= 0; t--) {
      if (dp[t])
        ans = min(ans, __builtin_popcount(t));
      else
        continue;
      P a[n][m];
      memset(a, -1, sizeof(a));
      for (int i = 0, k = 0; i < 20; i++) {
        if (t & (1 << i)) {
          a[k / m][k % m] = P(d[i], i);
          k++;
        }
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j].first == -1)
            break;
          for (int k = 0; k < 8; k++) {
            int x = i + dx[k], y = j + dy[k];
            if (!check(n, m, x, y))
              continue;
            if (a[i][j].first == a[x][y].first) {
              dp[t ^ (1 << a[i][j].second) ^ (1 << a[x][y].second)] |= dp[t];
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
bool check(int n, int m, int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}

bool dp[1 << 20];
int main() {
  int T, n = 5, m = 4;
  cin >> T;
  while (T--) {
    int d[20];
    for (int i = 0; i < 20; i++)
      cin >> d[i];
    memset(dp, 0, sizeof(dp));
    dp[(1 << 20) - 1] = 1;
    int ans = 1 << 29;
    for (int t = (1 << 20) - 1; t >= 0; t--) {
      if (dp[t])
        ans = min(ans, __builtin_popcount(t));
      P a[n][m];
      memset(a, -1, sizeof(a));
      for (int i = 0, k = 0; i < 20; i++) {
        if (t & (1 << i)) {
          a[k / m][k % m] = P(d[i], i);
          k++;
        }
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j].first == -1)
            continue;
          for (int k = 0; k < 8; k++) {
            int x = i + dx[k], y = j + dy[k];
            if (!check(n, m, x, y))
              continue;
            if (a[i][j].first == a[x][y].first) {
              dp[t ^ (1 << a[i][j].second) ^ (1 << a[x][y].second)] |= dp[t];
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00693 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n, m;
string S0[5000], S1[5000], S2[5000], T0[5000], T1[5000], T2[5000];
bool solve(string p1, string p2) {
  for (int i = 0; i < p1.size(); i++) {
    if (p1[i] != '?' && p1[i] != p2[i])
      return false;
  }
  return true;
}
int main() {
  while (true) {
    cin >> n >> m;
    vector<int> vec;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> S0[i] >> S1[i] >> S2[i];
    for (int i = 0; i < m; i++) {
      cin >> T1[i] >> T2[i] >> T0[i];
      for (int j = n - 1; j >= 0; j--) {
        bool P = solve(S1[j], T1[i]);
        if (P == true && solve(S2[j], T2[i]) == false)
          P = false;
        if (P == true && S0[j] == "deny")
          break;
        if (P == true && S0[j] == "permit") {
          vec.push_back(i);
          break;
        }
      }
    }
    cout << vec.size() << endl;
    for (int i = 0; i < vec.size(); i++)
      cout << T1[vec[i]] << ' ' << T2[vec[i]] << ' ' << T0[vec[i]] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n, m;
string S0[1000], S1[1000], S2[1000], T0[1000], T1[1000], T2[1000];
bool solve(string p1, string p2) {
  for (int i = 0; i < p1.size(); i++) {
    if (p1[i] != '?' && p1[i] != p2[i])
      return false;
  }
  return true;
}
int main() {
  while (true) {
    cin >> n >> m;
    vector<int> vec;
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> S0[i] >> S1[i] >> S2[i];
    for (int i = 0; i < m; i++) {
      cin >> T1[i] >> T2[i] >> T0[i];
      for (int j = n - 1; j >= 0; j--) {
        bool P = solve(S1[j], T1[i]);
        if (P == true && solve(S2[j], T2[i]) == false)
          P = false;
        if (P == true && S0[j] == "deny")
          break;
        if (P == true && S0[j] == "permit") {
          vec.push_back(i);
          break;
        }
      }
    }
    cout << vec.size() << endl;
    for (int i = 0; i < vec.size(); i++)
      cout << T1[vec[i]] << ' ' << T2[vec[i]] << ' ' << T0[vec[i]] << endl;
  }
  return 0;
}
Problem p00693 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool match(string s, string t) {
  for (int i = 0; i < 8; i++) {
    if (s[i] != '?' && s[i] != t[i])
      return false;
  }
  return true;
}
int n, m;
bool x[1111];
string r1[1111], r2[1111], a, b, c;
int main() {
  while (cin >> n >> m, n | m) {
    for (int i = 0; i < n; i++) {
      cin >> a >> r1[i] >> r2[i];
      if (a == "permit")
        x[i] = true;
      else
        x[i] = false;
    }
    int ret = 0;
    vector<string> v1, v2, v3;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c;
      bool p1 = false, p2 = false;
      for (int j = n - 1; j >= 0; j--) {
        if (match(r1[j], a) && match(r2[j], b)) {
          if (x[j])
            p1 = true;
          else
            p2 = true;
          break;
        }
      }
      if (p1) {
        v1.push_back(a);
        v2.push_back(b);
        v3.push_back(c);
        ret++;
      }
    }
    cout << ret << endl;
    for (int i = 0; i < ret; i++) {
      cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << endl;
    }
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool match(string s, string t) {
  for (int i = 0; i < 8; i++) {
    if (s[i] != '?' && s[i] != t[i])
      return false;
  }
  return true;
}
int n, m;
bool x[1111];
string r1[1111], r2[1111], a, b, c;
int main() {
  while (cin >> n >> m, n | m) {
    for (int i = 0; i < n; i++) {
      cin >> a >> r1[i] >> r2[i];
      if (a == "permit")
        x[i] = true;
      else
        x[i] = false;
    }
    int ret = 0;
    vector<string> v1, v2, v3;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c;
      bool p1 = false, p2 = false;
      for (int j = n - 1; j >= 0; j++) {
        if (match(r1[j], a) && match(r2[j], b)) {
          if (x[j])
            p1 = true;
          else
            p2 = true;
          break;
        }
      }
      if (p1) {
        v1.push_back(a);
        v2.push_back(b);
        v3.push_back(c);
        ret++;
      }
    }
    cout << ret << endl;
    for (int i = 0; i < ret; i++) {
      cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << endl;
    }
  }
}
Problem p00693 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pint;

string s[1024][3], ans[1024][3];
bool ck(string c1, string c2) {
  bool flag = true;
  rep(i, 8) {
    if (c2[i] == '?')
      continue;
    if (c1[i] != c2[i]) {
      flag = false;
      break;
    }
  }
  return flag;
}
int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    int cnt = 0;
    rep(i, n) cin >> s[i][0] >> s[i][1] >> s[i][2];
    rep(i, m) {
      string t1, t2, t3;
      cin >> t1 >> t2 >> t3;
      for (int j = n - 1; j >= 0; --j) {
        if (ck(t1, s[j][1]) && ck(t2, s[j][2])) {
          if (s[j][0][0] == 'p') {
            ans[cnt][0] = t1, ans[cnt][1] = t2, ans[cnt][2] = t3;
            ++cnt;
          }
          break;
        }
      }
    }
    cout << cnt << endl;
    rep(i, cnt) cout << ans[i][0] << ' ' << ans[i][1] << ' ' << ans[i][2]
                     << endl;
    ;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pint;

string s[1024][3], ans[1024][3];
bool ck(string c1, string c2) {
  bool flag = true;
  rep(i, 8) {
    if (c2[i] == '?')
      continue;
    if (c1[i] != c2[i]) {
      flag = false;
      break;
    }
  }
  return flag;
}
int main() {
  int n, m;
  while (cin >> n >> m, n) {
    int cnt = 0;
    rep(i, n) cin >> s[i][0] >> s[i][1] >> s[i][2];
    rep(i, m) {
      string t1, t2, t3;
      cin >> t1 >> t2 >> t3;
      rep(j, n) {
        if (ck(t1, s[j][1]) && ck(t2, s[j][2])) {
          if (s[j][0][0] == 'p') {
            ans[cnt][0] = t1, ans[cnt][1] = t2, ans[cnt][2] = t3;
            ++cnt;
          } else
            --cnt;
        }
      }
    }
    cout << cnt << endl;
    rep(i, cnt) cout << ans[i][0] << ' ' << ans[i][1] << ' ' << ans[i][2]
                     << endl;
    ;
  }
  return 0;
}
Problem p00693 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

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

using namespace std;

bool judge2(const char rule[51], const char packet[51]) {
  rep(i, 8) if (rule[i] != '?' && rule[i] != packet[i]) return false;
  return true;
}

bool judge(const char rule[3][51], const char packet[3][51]) {
  return judge2(rule[1], packet[0]) && judge2(rule[2], packet[1]);
}

int main() {
  for (int n, m; scanf("%d%d", &n, &m), n || m;) {
    static char rule[1024][3][51];
    rep(i, n) rep(j, 3) scanf("%s", rule[i][j]);

    int n_pass = 0, pass[1024];
    static char packet[1024][3][51];
    rep(k, m) {
      rep(j, 3) scanf("%s", packet[k][j]);

      bool ok = false;
      for (int i = n - 1; i >= 0; i--)
        if (judge(rule[i], packet[k])) {
          ok = (rule[i][0][0] == 'p');
          break;
        }

      if (ok)
        pass[n_pass++] = k;
    }

    printf("%d\\n", n_pass);
    rep(i, n_pass) printf("%s %s %s\\n", packet[pass[i]][0], packet[pass[i]][1],
                          packet[pass[i]][2]);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

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

using namespace std;

bool judge2(const char rule[51], const char packet[51]) {
  rep(i, 8) if (rule[i] != '?' && rule[i] != packet[i]) return false;
  return true;
}

bool judge(const char rule[3][51], const char packet[3][51]) {
  return judge2(rule[1], packet[0]) && judge2(rule[2], packet[1]);
}

int main() {
  for (int n, m; scanf("%d%d", &n, &m), n || m;) {
    char rule[50][3][51];
    rep(i, n) rep(j, 3) scanf("%s", rule[i][j]);

    int n_pass = 0, pass[50];
    char packet[50][3][51];
    rep(k, m) {
      rep(j, 3) scanf("%s", packet[k][j]);

      bool ok = false;
      for (int i = n - 1; i >= 0; i--)
        if (judge(rule[i], packet[k])) {
          ok = (rule[i][0][0] == 'p');
          break;
        }

      if (ok)
        pass[n_pass++] = k;
    }

    printf("%d\\n", n_pass);
    rep(i, n_pass) printf("%s %s %s\\n", packet[pass[i]][0], packet[pass[i]][1],
                          packet[pass[i]][2]);
  }

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

#include <cstring>
#include <iostream>

using namespace std;

bool match(char r[2][8], char ad[2][8]) {
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 8; j++) {
      if (r[i][j] != '?' && r[i][j] != ad[i][j])
        return false;
    }
  }
  return true;
}

int main() {
  int n, m;
  cin >> n >> m;
  while (n + m) {
    char c[100];
    cin.getline(c, sizeof c);
    char r[1024][2][8];
    bool p[1024] = {false};
    for (int i = 0; i < n; i++) {
      cin.getline(c, sizeof c);
      int idx = 0;
      while (c[idx++] != ' ')
        ;
      p[i] = c[0] == 'p';
      for (int j = 0; j < 8; j++) {
        r[i][0][j] = c[idx + j];
        r[i][1][j] = c[idx + 9 + j];
      }
    }
    int count = 0;
    char list[1024][100];
    for (int i = 0; i < m; i++) {
      char packet[100];
      cin.getline(packet, sizeof packet);
      char ad[2][8];
      for (int j = 0; j < 8; j++) {
        ad[0][j] = packet[j];
        ad[1][j] = packet[9 + j];
      }
      for (int j = n - 1; 0 <= j; j--) {
        if (match(r[j], ad)) {
          if (p[j])
            strcpy(list[count++], packet);
          break;
        }
      }
    }
    cout << count << endl;
    for (int i = 0; i < count; i++) {
      cout << list[i] << endl;
    }
    cin >> n >> m;
  }
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

bool match(char r[2][8], char ad[2][8]) {
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 8; j++) {
      if (r[i][j] != '?' && r[i][j] != ad[i][j])
        return false;
    }
  }
  return true;
}

int main() {
  int n, m;
  cin >> n >> m;
  while (n + m) {
    cin.ignore();
    char r[1024][2][8];
    bool p[1024] = {false};
    for (int i = 0; i < n; i++) {
      char c[100];
      cin.getline(c, sizeof c);
      int idx = 0;
      while (c[idx++] != ' ')
        ;
      p[i] = c[0] == 'p';
      for (int j = 0; j < 8; j++) {
        r[i][0][j] = c[idx + j];
        r[i][1][j] = c[idx + 9 + j];
      }
    }
    int count = 0;
    char list[1024][100];
    for (int i = 0; i < m; i++) {
      char packet[100];
      cin.getline(packet, sizeof packet);
      char ad[2][8];
      for (int j = 0; j < 8; j++) {
        ad[0][j] = packet[j];
        ad[1][j] = packet[9 + j];
      }
      for (int j = n - 1; 0 <= j; j--) {
        if (match(r[j], ad)) {
          if (p[j])
            strcpy(list[count++], packet);
          break;
        }
      }
    }
    cout << count << endl;
    for (int i = 0; i < count; i++) {
      cout << list[i] << endl;
    }
    cin >> n >> m;
  }
}