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

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

int num[101][101];
int dist[101][101];
#define INF 100000000

class state {
public:
  int now, money, cost;
  state(int now, int money, int cost) : now(now), cost(cost), money(money) {}
  bool operator<(const state &a) { return cost > a.cost; }
};

bool operator<(state a, state b) { return a.cost > b.cost; }

int main() {
  int n, m, l;
  while (cin >> n >> m >> l && n != 0) {

    int C[101][101];
    for (int i = 0; i < 101; i++)
      for (int j = 0; j < 101; j++)
        num[i][j] = dist[i][j] = C[i][j] = INF;

    for (int i = 0; i < m; i++) {
      int in, out, d, e;
      cin >> in >> out >> d >> e;
      num[in][out] = num[out][in] = e;
      dist[in][out] = dist[out][in] = d;
    }

    priority_queue<state> Q;
    Q.push(state(1, l, 0));
    while (!Q.empty()) {
      state t = Q.top();
      Q.pop();
      if (C[t.now][t.money] <= t.cost)
        continue;
      C[t.now][t.money] = t.cost;
      if (t.now == n) {
        cout << t.cost << endl;
        break;
      }
      for (int i = 1; i <= n; i++) {
        if (dist[t.now][i] < INF) {
          if (t.money - dist[t.now][i] >= 0)
            Q.push(state(i, t.money - dist[t.now][i], t.cost));
          Q.push(state(i, t.money, t.cost + num[t.now][i]));
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int num[101][101];
int dist[101][101];
#define INF 100000000

class state {
public:
  int now, money, cost;
  state(int now, int money, int cost) : now(now), cost(cost), money(money) {}
  bool operator<(const state &a) { return cost > a.cost; }
};

bool operator<(state a, state b) { return a.cost > b.cost; }

int main() {
  int n, m, l;
  while (cin >> n >> m >> l && n != 0) {

    int C[101][101];
    for (int i = 0; i < 101; i++)
      for (int j = 0; j < 101; j++)
        num[i][j] = dist[i][j] = C[i][j] = INF;

    for (int i = 0; i < m; i++) {
      int in, out, d, e;
      cin >> in >> out >> d >> e;
      num[in][out] = num[out][in] = e;
      dist[in][out] = dist[out][in] = d;
    }

    priority_queue<state> Q;
    Q.push(state(1, l, 0));
    while (!Q.empty()) {
      state t = Q.top();
      Q.pop();
      if (C[t.now][t.money] <= t.cost)
        continue;
      if (t.now == n) {
        cout << t.cost << endl;
        break;
      }
      for (int i = 1; i <= n; i++) {
        if (dist[t.now][i] < INF) {
          if (t.money - dist[t.now][i] >= 0)
            Q.push(state(i, t.money - dist[t.now][i], t.cost));
          Q.push(state(i, t.money, t.cost + num[t.now][i]));
        }
      }
    }
  }
  return 0;
}
Problem p01269 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;
typedef pair<int, pair<int, int>> E;    //(dest, (dist, cost))
typedef pair<int, pair<int, int>> Elem; //(-cost, (pos, money))

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

int main() {
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    vector<E> G[n];
    rep(i, m) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--, b--;
      G[a].push_back(make_pair(b, make_pair(d, e)));
      G[b].push_back(make_pair(a, make_pair(d, e)));
    }

    set<pair<int, int>> vis;
    priority_queue<Elem> q;
    q.push(make_pair(0, make_pair(0, l)));
    while (!q.empty()) {
      Elem e = q.top();
      int cost = -e.first;
      int pos = e.second.first;
      int money = e.second.second;
      q.pop();
      if (vis.find(make_pair(pos, money)) != vis.end())
        continue;
      vis.insert(make_pair(pos, money));
      if (money < 0)
        continue;
      if (pos == n - 1) {
        cout << cost << endl;
        break;
      }
      rep(i, G[pos].size()) {
        E edge = G[pos][i];
        int dest = edge.first;
        int dist = edge.second.first;
        int num = edge.second.second;
        q.push(make_pair(-cost, make_pair(dest, money - dist)));
        q.push(make_pair(-(cost + num), make_pair(dest, money)));
      }
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>

using namespace std;
typedef pair<int, pair<int, int>> E;    //(dest, (dist, cost))
typedef pair<int, pair<int, int>> Elem; //(-cost, (pos, money))

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

int main() {
  int n, m, l;
  while (cin >> n >> m >> l, n) {
    vector<E> G[n];
    rep(i, m) {
      int a, b, d, e;
      cin >> a >> b >> d >> e;
      a--, b--;
      G[a].push_back(make_pair(b, make_pair(d, e)));
      G[b].push_back(make_pair(a, make_pair(d, e)));
    }

    priority_queue<Elem> q;
    q.push(make_pair(0, make_pair(0, l)));
    while (!q.empty()) {
      Elem e = q.top();
      int cost = -e.first;
      int pos = e.second.first;
      int money = e.second.second;
      q.pop();

      if (money < 0)
        continue;
      if (pos == n - 1) {
        cout << cost << endl;
        break;
      }
      rep(i, G[pos].size()) {
        E edge = G[pos][i];
        int dest = edge.first;
        int dist = edge.second.first;
        int num = edge.second.second;
        q.push(make_pair(-cost, make_pair(dest, money - dist)));
        q.push(make_pair(-(cost + num), make_pair(dest, money)));
      }
    }
  }
  return 0;
}
Problem p01270 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

struct List {
  int id, cnt;
  List *nxt;
};

void _delete(List *p) {
  if (p == nullptr)
    return;
  _delete(p->nxt);
  delete p;
}

void erase(List *p, int id) {
  if (p == nullptr)
    return;
  if (p->id == id)
    p->id = -1;
  erase(p->nxt, id);
}

int find(List *p, int pos) {
  if (p == nullptr)
    return -1;
  if (p->cnt > pos)
    return p->id;
  return find(p->nxt, pos - p->cnt);
}

List *add(List *p, int id, int cnt) {
  if (!cnt)
    return p;
  if (p == nullptr)
    return new List{id, cnt, nullptr};
  if (p->id < 0) {
    p->id = id;
    if (p->cnt > cnt) {
      List *nl = new List{-1, p->cnt - cnt, p->nxt};
      p->cnt = cnt;
      p->nxt = nl;
      return p;
    }
    cnt -= p->cnt;
  }
  p->nxt = add(p->nxt, id, cnt);
  return p;
}

int main() {
  List *head = new List();
  int n;
  while (cin >> n, n) {
    while (n--) {
      char c;
      cin >> c;
      if (c == 'W') {
        int id, cnt;
        cin >> id >> cnt;
        head->nxt = add(head->nxt, id, cnt);
      } else if (c == 'D') {
        int id;
        cin >> id;
        erase(head->nxt, id);
      } else if (c == 'R') {
        int pos;
        cin >> pos;
        cout << find(head->nxt, pos) << '\\n';
      }
    }
    cout << '\\n';
    _delete(head->nxt);
    head->nxt = nullptr;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

struct List {
  int id, cnt;
  List *nxt;
};

void _delete(List *p) {
  if (p == nullptr)
    return;
  _delete(p->nxt);
  delete p;
}

void erase(List *p, int id) {
  if (p == nullptr)
    return;
  if (p->id == id)
    p->id = -1;
  erase(p->nxt, id);
}

int find(List *p, int pos) {
  if (p == nullptr)
    return -1;
  if (p->cnt > pos)
    return p->id;
  return find(p->nxt, pos - p->cnt);
}

List *add(List *p, int id, int cnt) {
  if (!cnt || p == nullptr)
    return new List{id, cnt, nullptr};
  if (p->id < 0) {
    p->id = id;
    if (p->cnt > cnt) {
      List *nl = new List{-1, p->cnt - cnt, p->nxt};
      p->nxt = nl;
      return p;
    }
    cnt -= p->cnt;
  }
  p->nxt = add(p->nxt, id, cnt);
  return p;
}

int main() {
  List *head = new List();
  int n;
  while (cin >> n, n) {
    while (n--) {
      char c;
      cin >> c;
      if (c == 'W') {
        int id, cnt;
        cin >> id >> cnt;
        head->nxt = add(head->nxt, id, cnt);
      } else if (c == 'D') {
        int id;
        cin >> id;
        erase(head->nxt, id);
      } else if (c == 'R') {
        int pos;
        cin >> pos;
        cout << find(head->nxt, pos) << '\\n';
      }
    }
    cout << '\\n';
    _delete(head->nxt);
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
  int i, j;
  int n;
  while (cin >> n, n) {
    pair<int, int> a[11000];
    int m = 0;
    fill(a, a + 11000, make_pair(-1, 1 << 30));
    for (i = 0; i < n; ++i) {
      char s;
      int p, q;
      cin >> s >> p;
      if (0) {
      } else if (s == 'W') {
        cin >> q;
        for (j = 0;;) {
          for (; a[j].first != -1; ++j)
            ;
          if (0) {
          } else if (a[j].second < q) {
            a[j].first = p;
            q -= a[j].second;
          } else if (a[j].second > q) {
            if (a[j].second != (1 << 30)) {
              copy_backward(a + j + 1, a + m, a + m + 1);
              a[j + 1] = make_pair(-1, a[j].second - q);
            }
            ++m;
            a[j] = make_pair(p, q);
            break;
          } else {
            a[j] = make_pair(p, q);
            break;
          }
        }
      } else if (s == 'D') {
        for (j = 0; j < m; ++j) {
          if (a[j].first == p)
            a[j].first = -1;
        }
      } else if (s == 'R') {
        long long sm = 0;
        for (j = 0; p >= sm + a[j].second; ++j)
          sm += a[j].second;
        cout << a[j].first << endl;
      }
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <string>
using namespace std;
list<pair<int, int>> a;
int main() {
  int h, i, j;
  int n, p, q;
  char c;
  list<pair<int, int>>::iterator it;
  h = 0;
  while (cin >> n && n) {
    if (h)
      cout << endl;
    else
      h = 1;
    a.clear();
    a.push_back(make_pair(-1, 1000000000));
    for (i = 0; i < n; i++) {
      cin >> c;
      if (0) {
      } else if (c == 'W') {
        cin >> p >> q;
        for (it = a.begin(); q; it++) {
          if ((*it).first == -1) {
            if (0) {
            } else if ((*it).second < q) {
              (*it).first = p;
              q -= (*it).second;
            } else if ((*it).second > q) {
              (*it).second -= q;
              a.insert(it, make_pair(p, q));
              q = 0;
            } else {
              (*it).first = p;
              q = 0;
            }
          }
        }
      } else if (c == 'D') {
        cin >> p;
        for (it = a.begin(); it != a.end(); it++) {
          if ((*it).first == p)
            (*it).first = -1;
        }
      } else if (c == 'R') {
        cin >> p;
        j = 1;
        for (it = a.begin();; it++) {
          if (j <= p && p < j + (*it).second) {
            cout << (*it).first << endl;
            break;
          }
          j += (*it).second;
        }
      }
    }
  }
  return 0;
}
Problem p01270 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long lli;

struct Data {
  lli size, id;
};

int main() {
  int N;
  while (cin >> N && N) {
    vector<Data> v;
    while (N--) {
      char op;
      cin >> op;
      if (op == 'W') {
        lli l, S;
        cin >> l >> S;
        for (int i = 0; S && i < v.size(); ++i) {
          if (v[i].id == -2) {
            v[i].id = l;
            if (v[i].size > S) {
              lli r = v[i].size - S;
              v[i].size = S;
              v.insert(v.begin() + i + 1, (Data){r, -2});
            }
            S -= v[i].size;
          }
        }
        if (S) {
          v.push_back((Data){S, l});
        }
      } else if (op == 'D') {
        lli l;
        cin >> l;
        for (int i = 0; i < v.size(); ++i) {
          if (v[i].id == l)
            v[i].id = -2;
        }
      } else if (op == 'R') {
        lli P;
        cin >> P;
        lli output = -1;
        for (lli i = 0, sum = 0; i < v.size(); sum += v[i++].size) {
          if (P < sum + v[i].size) {
            if (v[i].id >= 0)
              output = v[i].id;
            break;
          }
        }
        cout << output << endl;
      }
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

typedef long long lli;

struct Data {
  lli size, id;
};

int main() {
  int N;
  while (cin >> N && N) {
    vector<Data> v;
    while (N--) {
      char op;
      cin >> op;
      if (op == 'W') {
        lli l, S;
        cin >> l >> S;
        for (int i = 0; i < v.size(); ++i) {
          if (v[i].id == -2) {
            v[i].id = l;
            if (v[i].size > S) {
              lli r = v[i].size - S;
              v[i].size = S;
              v.insert(v.begin() + i + 1, (Data){r, -2});
            }
            S -= v[i].size;
          }
        }
        if (S) {
          v.push_back((Data){S, l});
        }
      } else if (op == 'D') {
        lli l;
        cin >> l;
        for (int i = 0; i < v.size(); ++i) {
          if (v[i].id == l)
            v[i].id = -2;
        }
      } else if (op == 'R') {
        lli P;
        cin >> P;
        --P;
        lli output = -1;
        for (lli i = 0, sum = 0; i < v.size(); sum += v[i++].size) {
          if (P < sum + v[i].size) {
            if (v[i].id >= 0)
              output = v[i].id;
            break;
          }
        }
        cout << output << endl;
      }
      /*
      for(int i = 0; i < v.size(); ++i) {
        cout << v[i].id << " " << v[i].size << endl;
      }
      cout << "-----------" << endl;
      */
    }
    cout << endl;
  }
  return 0;
}
Problem p01270 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define mp make_pair
using namespace std;
typedef map<pair<int, int>, int> S;
int main() {
  int n, t1, t2;
  char c;
  while (cin >> n, n) {
    S s;
    rep(i, n) {
      cin >> c;
      if (c == 'W') {
        cin >> t1 >> t2;
        int p = 0, q;
        if (s.empty())
          s.insert(mp(mp(0, t2), t1)), t2 = 0;
        else {
          foreach (j, s) {
            if (j->first.first > p) {
              q = min(p + t2, j->first.first);
              s.insert(mp(mp(p, q), t1));
              t2 -= q - p;
              p = q;
              j--;
            } else
              p = j->first.second;
            if (t2 == 0)
              break;
          }
          if (t2 > 0)
            s.insert(mp(mp(p, p + t2), t1));
        }
      } else if (c == 'D') {
        cin >> t1;
        foreach (j, s)
          if (j->second == t1)
            s.erase(j);
      } else {
        cin >> t1;
        foreach (j, s)
          if (j->first.first <= t1 && t1 < j->first.second) {
            cout << j->second << endl;
            goto END;
          }
        cout << -1 << endl;
      END:;
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define mp make_pair
using namespace std;
typedef map<pair<int, int>, int> S;
int main() {
  int n, t1, t2;
  char c;
  while (cin >> n, n) {
    S s;
    rep(i, n) {
      cin >> c;
      if (c == 'W') {
        cin >> t1 >> t2;
        int p = 0, q;
        if (s.empty())
          s.insert(mp(mp(0, t2), t1)), t2 = 0;
        else {
          foreach (j, s) {
            if (j->first.first > p) {
              q = min(p + t2, j->first.first);
              s.insert(mp(mp(p, q), t1));
              t2 -= q - p;
              p = q;
              j--;
            } else
              p = j->first.second;
          }
          if (t2 > 0)
            s.insert(mp(mp(p, p + t2), t1));
        }
      } else if (c == 'D') {
        cin >> t1;
        foreach (j, s)
          if (j->second == t1)
            s.erase(j);
      } else {
        cin >> t1;
        foreach (j, s)
          if (j->first.first <= t1 && t1 < j->first.second) {
            cout << j->second << endl;
            goto END;
          }
        cout << -1 << endl;
      END:;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p01270 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

const ll INF = 1LL << 60;

int main() {
  int n;
  while (cin >> n, n) {
    PQ que;
    que.push(P(0LL, INF));
    map<P, ll> m;
    while (n--) {
      char c;
      cin >> c;
      if (c == 'W') {
        ll t, l;
        cin >> t >> l;
        P p;
        while (true) {
          p = que.top();
          que.pop();
          ll s = p.first, g = p.second;
          if (s + l - 1 <= g) {
            if (s + l - 1 < g)
              que.push(P(s + l, g));
            m[P(s, s + l - 1)] = t;
            break;
          } else {
            m[P(s, g)] = t;
            l -= g - s + 1;
          }
        }
      } else if (c == 'D') {
        ll t;
        cin >> t;
        auto tmp(m);
        for (auto i : tmp) {
          if (i.second == t) {
            que.push(i.first);
            m.erase(m.find(i.first));
          }
        }
      } else {
        ll x;
        cin >> x;
        bool flag = true;
        for (auto i : m) {
          if (i.first.first <= x && x <= i.first.second) {
            cout << i.second << endl;
            flag = false;
            break;
          }
        }
        if (flag)
          cout << -1 << endl;
      }
    }
    cout << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

typedef pair<int, int> P;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

const int INF = 1 << 28;

int main() {
  int n;
  while (cin >> n, n) {
    PQ que;
    que.push(P(0, INF));
    map<P, int> m;
    while (n--) {
      char c;
      cin >> c;
      if (c == 'W') {
        int t, l;
        cin >> t >> l;
        P p;
        while (true) {
          p = que.top();
          que.pop();
          int s = p.first, g = p.second;
          if (s + l - 1 <= g) {
            if (s + l - 1 < g)
              que.push(P(s + l, g));
            m[P(s, s + l - 1)] = t;
            break;
          } else {
            m[P(s, g)] = t;
            l -= g - s + 1;
          }
        }
      } else if (c == 'D') {
        int t;
        cin >> t;
        for (auto i : m) {
          if (i.second == t) {
            que.push(i.first);
            m.erase(m.find(i.first));
          }
        }
      } else {
        int x;
        cin >> x;
        bool flag = true;
        for (auto i : m) {
          if (i.first.first <= x && x <= i.first.second) {
            cout << i.second << endl;
            flag = false;
            break;
          }
        }
        if (flag)
          cout << -1 << endl;
      }
    }
    cout << endl;
  }

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

#include <iostream>
#define REP(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;

struct sector {
  ll l, r, f;
};

ll N, I, S, P;
char C;
sector a[20000];
int k;

void write() {
  cin >> I >> S;
  REP(i, 0, k) if (a[i].f == -1 && S > 0) {
    if (S >= a[i].r - a[i].l) {
      a[i].f = I;
      S -= a[i].r - a[i].l;
    } else {
      for (int j = k; j > i; j--) {
        a[j + 1].l = a[j].l;
        a[j + 1].r = a[j].r;
        a[j + 1].f = a[j].f;
      }
      a[i + 1].r = a[i].r;
      a[i + 1].f = -1;
      a[i].f = I;
      a[i].r = a[i].l + S;
      a[i + 1].l = a[i].r;
      S = 0;
      k++;
      break;
    }
  }
  if (S > 0) {
    int l = k > 0 ? a[k - 1].r : 0;
    a[k++] = (sector){l, l + S, I};
  }
}

void destroy() {
  cin >> I;
  REP(i, 0, k) if (a[i].f == I) a[i].f = -1;
}

ll read() {
  cin >> P;
  REP(i, 0, k) if (a[i].l <= P && P < a[i].r) return a[i].f;
  return -1;
}

int main(void) {
  while (cin >> N, N) {
    k = 0;
    REP(i, 0, N) {
      cin >> C;
      if (C == 'W')
        write();
      if (C == 'D')
        destroy();
      if (C == 'R')
        cout << read() << endl;

      // cout << i << ": " << C << " " << k << endl;
      // REP(i, 0, k) {
      //   cout << a[i].l << " - " << a[i].r << ": " << a[i].f << endl;
      // }
      // cout << endl;
    }
    cout << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
#define REP(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;

struct sector {
  ll l, r, f;
};

ll N, I, S, P;
char C;
sector a[1000];
int k;

void write() {
  cin >> I >> S;
  REP(i, 0, k) if (a[i].f == -1 && S > 0) {
    if (S >= a[i].r - a[i].l) {
      a[i].f = I;
      S -= a[i].r - a[i].l;
    } else {
      for (int j = k; j > i; j--) {
        a[j + 1].l = a[j].l;
        a[j + 1].r = a[j].r;
        a[j + 1].f = a[j].f;
      }
      a[i + 1].r = a[i].r;
      a[i + 1].f = -1;
      a[i].f = I;
      a[i].r = a[i].l + S;
      a[i + 1].l = a[i].r;
      S = 0;
      k++;
      break;
    }
  }
  if (S > 0) {
    int l = k > 0 ? a[k - 1].r : 0;
    a[k++] = (sector){l, l + S, I};
  }
}

void destroy() {
  cin >> I;
  REP(i, 0, k) if (a[i].f == I) a[i].f = -1;
}

ll read() {
  cin >> P;
  REP(i, 0, k) if (a[i].l <= P && P < a[i].r) return a[i].f;
  return -1;
}

int main(void) {
  while (cin >> N, N) {
    k = 0;
    REP(i, 0, N) {
      cin >> C;
      if (C == 'W')
        write();
      if (C == 'D')
        destroy();
      if (C == 'R')
        cout << read() << endl;

      // cout << i << ": " << C << " " << k << endl;
      // REP(i, 0, k) {
      //   cout << a[i].l << " - " << a[i].r << ": " << a[i].f << endl;
      // }
      // cout << endl;
    }
    cout << endl;
  }
}