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

#include <bits/stdc++.h>

using namespace std;

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

const int INF = 1 << 29;

int N, R;
int A[3000], B[3000], D[3000];
int cost[1500][1500];
bool used[1500], v[1500];
vector<int> g[1500];

void dfs(int idx, int *dist) {
  if (v[idx]++)
    return;
  used[idx]++;
  for (auto &i : g[idx]) {
    if (A[i] == idx && dist[B[i]] + D[i] == dist[idx])
      dfs(B[i], dist);
    if (B[i] == idx && dist[A[i]] + D[i] == dist[idx])
      dfs(A[i], dist);
  }
}

int main() {
  fill_n(*cost, 1500 * 1500, INF);
  rep(i, 1500) cost[i][i] = 0;

  cin >> N >> R;
  rep(i, R) {
    cin >> A[i] >> B[i] >> D[i];
    --A[i], --B[i];
    cost[A[i]][B[i]] = cost[B[i]][A[i]] = D[i];
    g[A[i]].push_back(i);
    g[B[i]].push_back(i);
  }
  rep(i, N) rep(j, N) rep(k, N) cost[j][k] =
      min(cost[j][k], cost[j][i] + cost[i][k]);

  int ret = 0;
  rep(i, N) rep(j, N) if (cost[i][j] != INF) ret = max(ret, cost[i][j]);

  rep(i, N) {
    memset(v, false, sizeof(v));
    rep(j, N) if (cost[i][j] == ret) dfs(j, cost[i]);
  }
  cout << count(used, used + N, false) << endl;
  rep(i, N) if (!used[i]) cout << i + 1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

const int INF = 1 << 29;

int N, R;
int A[3000], B[3000], D[3000];
int cost[1500][1500];
bool used[1500], v[1500];
vector<int> g[1500];

void dfs(int idx, int *dist) {
  if (v[idx]++)
    return;
  used[idx]++;
  for (auto &i : g[idx]) {
    if (A[i] == idx && dist[B[i]] + D[i] == dist[idx])
      dfs(B[i], dist);
    if (B[i] == idx && dist[A[i]] + D[i] == dist[idx])
      dfs(A[i], dist);
  }
}

int main() {
  fill_n(*cost, 1500 * 1500, INF);
  rep(i, 1500) cost[i][i] = 0;

  cin >> N >> R;
  rep(i, R) {
    cin >> A[i] >> B[i] >> D[i];
    --A[i], --B[i];
    cost[A[i]][B[i]] = cost[B[i]][A[i]] = D[i];
    g[A[i]].push_back(i);
    g[B[i]].push_back(i);
  }
  rep(i, N) rep(j, N) rep(k, N) cost[j][k] =
      min(cost[j][k], cost[j][i] + cost[i][k]);

  int ret = 0;
  rep(i, N) rep(j, N) if (cost[i][j] != INF) ret = max(ret, cost[i][j]);

  rep(i, N) rep(j, N) {
    memset(v, false, sizeof(v));
    if (cost[i][j] == ret)
      dfs(j, cost[i]);
  }
  cout << count(used, used + N, false) << endl;
  rep(i, N) if (!used[i]) cout << i + 1 << endl;
}
Problem p00347 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int w, h;
int dp[2000][2000][2], s[2000][2000];
int sum[2000][2000];
int dx[]{1, 0}, dy[]{0, 1};

int rec(int x, int y, int a) {
  if (dp[x][y][a] != -1)
    return dp[x][y][a];
  if (y == w)
    return 0;
  int res = (a == 0 ? INT_MIN : INT_MAX);
  rep(i, 2) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx > h)
      continue;
    int b = rec(nx, ny, !a) + (i == 1 ? sum[x][y] : 0);
    if (a == 0)
      res = max(res, b);
    else
      res = min(res, b);
  }
  return dp[x][y][a] = res;
}
int main() {
  scanf("%d%d", &w, &h);
  rep(i, h) rep(j, w) scanf("%d", &s[i][j]);
  int a = 0;
  rep(i, w) rep(j, h) {
    sum[j + 1][i] = sum[j][i] + s[j][i];
    a += s[j][i];
  }
  memset(dp, -1, sizeof(dp));
  cout << abs(a - rec(0, 0, 0) * 2) << endl;
}

Error: TLE

Fixed submission:

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

int w, h;
int dp[2000][2000][2], s[2000][2000];
int sum[2000][2000];
int dx[]{1, 0}, dy[]{0, 1};

int rec(int x, int y, int a) {
  if (dp[x][y][a] != -1)
    return dp[x][y][a];
  if (y == w)
    return 0;
  int res = (a == 0 ? INT_MIN : INT_MAX);
  rep(i, 2) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx > h)
      continue;
    int b = rec(nx, ny, !a) + (i == 1 ? sum[x][y] : 0);
    if (a == 0)
      res = max(res, b);
    else
      res = min(res, b);
  }
  return res;
}
int main() {
  scanf("%d%d", &w, &h);
  rep(i, h) rep(j, w) scanf("%d", &s[i][j]);
  int a = 0;
  rep(i, w) rep(j, h) {
    sum[j + 1][i] = sum[j][i] + s[j][i];
    a += s[j][i];
  }
  memset(dp, -1, sizeof(dp));
  cout << abs(a - rec(0, 0, 0) * 2) << endl;
}
Problem p00348 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>

using namespace std;

#define long long long

const int N = 2e5 + 2;

int n, a[N];
queue<set<int> *> q;

set<int> *Merge(set<int> *a, set<int> *b) {
  if (a->size() < b->size())
    return Merge(b, a);
  for (int x : *b)
    a->insert(x);
  b->clear();
  return a;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    set<int> *s = new set<int>();
    s->insert(a[i]);
    q.push(s);
  }
  sort(a + 1, a + 1 + n);
  long res = 0;
  for (int i = 1; i <= n; ++i) {
    set<int> *s = new set<int>();
    do {
      s = Merge(s, q.front());
      q.pop();
    } while (s->find(a[i]) == s->end());
    s->erase(a[i]);
    res += s->size();
    q.push(s);
  }
  printf("%lld\\n", res);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>

using namespace std;

#define long long long

const int N = 2e5 + 2;

int n, a[N];
queue<set<int>> q;

set<int> &Merge(set<int> &a, set<int> &b) {
  if (a.size() < b.size())
    return Merge(b, a);
  for (int x : b)
    a.insert(x);
  b.clear();
  return a;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    set<int> s;
    s.insert(a[i]);
    q.push(s);
  }
  sort(a + 1, a + 1 + n);
  long res = 0;
  for (int i = 1; i <= n; ++i) {
    set<int> s;
    do {
      set<int> r = move(q.front());
      q.pop();
      s = Merge(s, r);
    } while (s.find(a[i]) == s.end());
    s.erase(a[i]);
    res += s.size();
    q.push(move(s));
  }
  printf("%lld\\n", res);
  return 0;
}
Problem p00348 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using LL = long long;

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

  list<int> l;
  queue<unique_ptr<set<int>>> q;
  for (auto i = 0; i < N; ++i) {
    int a;
    cin >> a;
    l.emplace_back(a);
    q.emplace(make_unique<set<int>>());
    q.back()->emplace(a);
  }

  auto merge = [](auto &base, auto &add) {
    if (base->size() < add->size())
      swap(base, add);
    base->insert(begin(*add), end(*add));
  };

  LL answer = 0;
  l.sort();
  while (!l.empty()) {
    unique_ptr<set<int>> nex = make_unique<set<int>>();
    while (l.front() != *begin(*q.front())) {
      auto s = move(q.front());
      q.pop();
      merge(nex, s);
    }
    merge(nex, q.front());
    q.pop();
    nex->erase(l.front());
    l.pop_front();
    answer += nex->size();
    if (!nex->empty())
      q.emplace(move(nex));
  }
  cout << answer << endl;
}

Error: TLE

Fixed submission:

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

using LL = long long;

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

  list<int> l;
  queue<set<int>> q;
  for (auto i = 0; i < N; ++i) {
    int a;
    cin >> a;
    l.emplace_back(a);
    q.push({a});
  }

  auto merge = [](auto &base, auto &add) {
    if (base.size() < add.size())
      swap(base, add);
    base.insert(begin(add), end(add));
  };

  LL answer = 0;
  l.sort();
  while (!l.empty()) {
    set<int> nex;
    while (l.front() != *begin(q.front())) {
      auto s = q.front();
      q.pop();
      merge(nex, s);
    }
    merge(nex, q.front());
    q.pop();
    nex.erase(l.front());
    l.pop_front();
    answer += nex.size();
    if (!nex.empty())
      q.push(nex);
  }
  cout << answer << endl;
}
Problem p00348 (C++) — buggy submission, verdict: Runtime Error

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0353

#include <bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;

typedef priority_queue<int, vector<int>, greater<int>> PQ;
PQ mq[2 * N];
int l, r, n, a[N], p[N];
long long ans;

void Union(PQ &a, PQ &b) {
  if (a.size() < b.size())
    a.swap(b);
  while (b.size()) {
    a.push(b.top());
    b.pop();
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  l = 1;
  r = n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    p[i] = i;
  sort(p + 1, p + 1 + n, [](int x, int y) { return a[x] < a[y]; });
  for (int i = 1; i <= n; i++)
    a[p[i]] = i;
  for (int i = 1; i <= n; i++)
    mq[i].push(a[i]);
  for (int i = 1; i <= n; i++) {
    for (; l <= r; l++) {
      if (mq[l].top() == i)
        break;
      Union(mq[l + 1], mq[l]);
    }
    if (mq[l].size() != 1) {
      r++;
      mq[r].swap(mq[l]);
      mq[r].pop();
      ans += mq[r].size();
    }
    l++;
  }
  cout << ans << "\\n";
}


Error: 0

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0353

#include <bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;

typedef priority_queue<int, vector<int>, greater<int>> PQ;
PQ mq[2 * N];
int l, r, n, a[N], p[N], ans;

void Union(PQ &a, PQ &b) {
  if (a.size() < b.size())
    a.swap(b);
  while (b.size()) {
    a.push(b.top());
    b.pop();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  l = 1;
  r = n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    p[i] = i;
  sort(p + 1, p + 1 + n, [](int x, int y) { return a[x] < a[y]; });
  for (int i = 1; i <= n; i++)
    a[p[i]] = i;
  for (int i = 1; i <= n; i++)
    mq[i].push(a[i]);
  for (int i = 1; i <= n; i++) {
    for (; l <= r; l++) {
      if (mq[l].top() == i)
        break;
      Union(mq[l + 1], mq[l]);
    }
    if (mq[l].size() != 1) {
      r++;
      mq[r].swap(mq[l]);
      mq[r].pop();
      ans += mq[r].size();
    }
    l++;
  }
  cout << ans << "\\n";
}
Problem p00348 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>

#define ff(i, a, b) for (int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
typedef set<int> sI;
const int N = 2e5 + 10;
int n, a[N], b[N];
queue<sI *> Q;

int main() { /*
     freopen("9.inp","r",stdin); freopen("9.out","w",stdout); //*/
  scanf("%d", &n);
  ff(i, 1, n) scanf("%d", &a[i]);
  copy(a + 1, a + n + 1, b + 1);
  sort(b + 1, b + n + 1);
  ff(i, 1, n) {
    sI *s = new sI;
    s->insert(a[i]);
    Q.push(s);
  }
  ll ans = 0ll;
  for (int i = 1; i <= n; i++) {
    sI *ps = Q.front();
    Q.pop();
    while (ps->count(b[i]) == 0) {
      sI *t = Q.front();
      Q.pop();
      for (sI::iterator it = t->begin(); it != t->end(); it++) {
        ps->insert(*it);
      }
      t->clear();
    }
    ps->erase(b[i]);
    ans += (int)ps->size();
    Q.push(ps);
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>

#define ff(i, a, b) for (int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
typedef set<int> sI;
const int N = 2e5 + 10;
int n, a[N], b[N];
queue<sI> Q;

int main() { /*
     freopen("9.inp","r",stdin); freopen("9.out","w",stdout); //*/
  scanf("%d", &n);
  ff(i, 1, n) scanf("%d", &a[i]);
  copy(a + 1, a + n + 1, b + 1);
  sort(b + 1, b + n + 1);
  ff(i, 1, n) {
    sI s;
    s.insert(a[i]);
    Q.push(s);
  }
  ll ans = 0ll;
  for (int i = 1; i <= n; i++) {
    sI s = Q.front();
    Q.pop();
    while (s.count(b[i]) == 0) {
      sI t = Q.front();
      Q.pop();
      for (sI::iterator it = t.begin(); it != t.end(); it++) {
        s.insert(*it);
      }
    }
    s.erase(b[i]);
    ans += (int)s.size();
    Q.push(s);
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p00348 (C++) — buggy submission, verdict: Time Limit Exceeded

/*input
6
6 5 4 3 2 1
*/
#include <bits/stdc++.h>
using namespace std;

typedef priority_queue<int, vector<int>, greater<int>> Dat;
queue<Dat> q;

void Merge(Dat &a, Dat &b) {
  if (a.size() < b.size())
    a.swap(b);
  while (b.size())
    a.push(b.top()), b.pop();
}

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

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    Dat cur;
    cur.push(a[i]);
    q.push(cur);
  }

  sort(a.begin(), a.end());
  long long Ans = 0;
  for (int i = 0; i < n; ++i) {
    Dat cur = std::move(q.front());
    q.pop();

    while (cur.top() != a[i])
      Merge(cur, q.front()), q.pop();

    cur.pop();
    if (cur.size())
      Ans += cur.size(), q.push(std::move(cur));
  }
  printf("%lld\\n", Ans);
}


Error: TLE

Fixed submission:

/*input
6
6 5 4 3 2 1
*/
#include <bits/stdc++.h>
using namespace std;

typedef set<int> Dat;

void Merge(Dat &a, Dat &b) {
  if (a.size() < b.size())
    a.swap(b);
  for (int v : b)
    a.insert(v);
}

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

  queue<Dat> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    Dat cur;
    cur.insert(a[i]);
    q.push(cur);
  }

  sort(a.begin(), a.end());
  long long Ans = 0;
  for (int i = 0; i < n; ++i) {
    Dat cur = move(q.front());
    q.pop();

    while (*cur.begin() != a[i]) {
      Dat tmp = q.front();
      q.pop();
      Merge(cur, tmp);
    }

    cur.erase(cur.begin());
    if (cur.size())
      Ans += cur.size(), q.push(cur);
  }
  printf("%lld\\n", Ans);
}
Problem p00348 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <vector>

const int LIM = 2e5 + 5;

int n, dsu[LIM], a[LIM], b[LIM];
long long ans;
std::map<int, int> map;
std::queue<int> q;

int root(int x) {
  if (dsu[x] <= 0)
    return x;
  else
    return dsu[x] = root(dsu[x]);
}

void merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) {
    if (dsu[x] < dsu[y])
      std::swap(x, y);
    dsu[y] += dsu[x];
    dsu[x] = y;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }

  std::sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i)
    map[b[i]] = i;
  for (int i = 1; i <= n; ++i)
    a[i] = map[a[i]];
  a[n + 1] = n + 1;

  memset(dsu, 0xff, sizeof(dsu));
  for (int i = 1; i <= n; ++i)
    q.push(a[i]);

  for (int i = 1; i <= n; ++i) {
    int s = root(q.front());
    q.pop();
    while (root(i) != root(s)) {
      merge(s, q.front());
      q.pop();
    }
    ans -= ++dsu[root(s)];
    //		printf("%d -> %d\\n", i, -dsu[root(s)]);
    q.push(root(s));
  }
  printf("%lld\\n", ans);
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <vector>

const int LIM = 1e5 + 5;

int n, dsu[LIM], a[LIM], b[LIM];
long long ans;
std::map<int, int> map;
std::queue<int> q;

int root(int x) {
  if (dsu[x] <= 0)
    return x;
  else
    return dsu[x] = root(dsu[x]);
}

void merge(int x, int y) {
  x = root(x);
  y = root(y);
  if (x != y) {
    if (dsu[x] < dsu[y])
      std::swap(x, y);
    dsu[y] += dsu[x];
    dsu[x] = y;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }

  std::sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i)
    map[b[i]] = i;
  for (int i = 1; i <= n; ++i)
    a[i] = map[a[i]];
  a[n + 1] = n + 1;

  memset(dsu, 0xff, sizeof(dsu));
  for (int i = 1; i <= n; ++i)
    q.push(a[i]);

  for (int i = 1; i <= n; ++i) {
    int s = root(q.front());
    q.pop();
    while (root(i) != root(s)) {
      merge(s, q.front());
      q.pop();
    }
    ans -= ++dsu[root(s)];
    //		printf("%d -> %d\\n", i, -dsu[root(s)]);
    q.push(root(s));
  }
  printf("%lld\\n", ans);
}
Problem p00349 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <utility>

#define ff(i, a, b) for (int i = (a); i <= (b); i++)
using namespace std;
typedef pair<int, int> ii;
const int N = 2e5 + 10;
int w, h, n;
struct kien {
  int x, y, huong, id;
};
ii T[N];
int tmp[N];
kien a[N];
int cmpVal(const kien &k) {
  if (k.huong == 0) /// Đông
    return (k.x & 1) ? 3 : 1;
  return (k.x & 1) ? 2 : 4;
}
bool cmpKien(const kien &k1, const kien &k2) {
  /// Đầu tiên sort theo đường chéo.
  if (k1.x + k1.y != k2.x + k2.y)
    return k1.x + k1.y < k2.x + k2.y;

  int xxk1 = (k1.x & 1), xxk2 = (k2.x & 1);
  if (((k1.x + k1.y) & 1) == 0) { /// Ô trắng.
    if (xxk1 != xxk2)
      return xxk1 < xxk2;
    else
      return k1.huong < k2.huong;
  } else {
    int tmp1 = cmpVal(k1), tmp2 = cmpVal(k2);
    return tmp1 < tmp2;
  }
}
bool cungNhom(const kien &k1, const kien &k2) {
  if (k1.x + k1.y != k2.x + k2.y)
    return 0;
  int xxk1 = k1.x & 1, xxk2 = k2.x & 1;
  if (!((k1.x + k1.y) & 1)) {
    return xxk1 == xxk2;
  }
  int val1 = (k1.huong << 1) + xxk1, val2 = (k2.huong << 1) + xxk2;
  return ((val1 ^ val2) == 0 || (val1 ^ val2) == 3);
}
bool cmp2(const kien &k1, const kien &k2) {
  if (k1.huong != k2.huong)
    return k1.huong < k2.huong;
  if (k1.huong == 0)
    return k1.y < k2.y;
  else
    return k1.x > k2.x;
}
int tgRoi(const kien &k) { return (k.huong == 0) ? w - k.x : h - k.y; }
bool cmp3(const kien &k1, const kien &k2) { return k1.x - k1.y > k2.x - k2.y; }
int main() { /*
     freopen("10.inp","r",stdin); freopen("10.out","w",stdout); //*/
  scanf("%d %d %d\\n", &w, &h, &n);
  ff(i, 1, n) {
    int x, y;
    char c;
    scanf("%d %d %c\\n", &x, &y, &c);
    a[i] = {x, y, (c == 'E') ? 0 : 1, i};
  }
  sort(a + 1, a + n + 1, cmpKien);
  int l = 1, r = 1;
  do {
    if (l > n)
      break;
    while (r <= n && cungNhom(a[l], a[r]))
      r++;
    sort(a + l, a + r, cmp2);
    ff(i, l, r - 1) tmp[i] = tgRoi(a[i]);
    sort(a + l, a + r, cmp3);
    ff(i, l, r - 1) T[a[i].id] = ii(tmp[i], a[i].id);
    l = r;
  } while (1);
  sort(T + 1, T + n + 1);
  ff(i, 1, n) printf("%d\\n", T[i].second);
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>

#define ff(i, a, b) for (int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
typedef set<int> sI;
const int N = 2e5 + 10;
int n, a[N], b[N];
queue<sI> Q;

int main() { /*
     freopen("9.inp","r",stdin); freopen("9.out","w",stdout); //*/
  scanf("%d", &n);
  ff(i, 1, n) scanf("%d", &a[i]);
  copy(a + 1, a + n + 1, b + 1);
  sort(b + 1, b + n + 1);
  ff(i, 1, n) {
    sI s;
    s.insert(a[i]);
    Q.push(s);
  }
  ll ans = 0ll;
  for (int i = 1; i <= n; i++) {
    sI s = Q.front();
    Q.pop();
    while (s.count(b[i]) == 0) {
      sI t = Q.front();
      Q.pop();
      for (sI::iterator it = t.begin(); it != t.end(); it++) {
        s.insert(*it);
      }
    }
    s.erase(b[i]);
    ans += (int)s.size();
    Q.push(s);
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p00354 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int X;
  cin >> X;
  if (X % 7 == 0) {
    cout << "thu" << endl;
  }
  if (X % 7 == 1) {
    cout << "fri" << endl;
  }
  if (X % 7 == 2) {
    cout << "sat" << endl;
  }
  if (X % 7 == 3) {
    cout << "sun" << endl;
  }
  if (X % 7 == 4) {
    cout << "mon" << endl;
  }
  if (X % 7 == 5) {
    cout << "tue" << endl;
  }
  if (X % 7 == 6) {
    cout << "wed" << endl;
  }

  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int X;
  cin >> X;
  if (X % 0) {
    cout << "thu" << endl;
  }
  if (X % 1) {
    cout << "fri" << endl;
  }
  if (X % 2) {
    cout << "sat" << endl;
  }
  if (X % 3) {
    cout << "sun" << endl;
  }
  if (X % 4) {
    cout << "mon" << endl;
  }
  if (X % 5) {
    cout << "tue" << endl;
  }
  if (X % 6) {
    cout << "wed" << endl;
  }

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

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll a;
  string result;
  cin >> a;
  a %= 7;
  if (a == 1)
    result = "fri";
  else if (a == 2)
    result = "sat";
  else if (a == 3)
    result = "sun";
  else if (a == 4)
    result = "mon";
  else if (a == 5)
    result = "tue";
  else if (a == 6)
    result = "wed";
  else if (a == 0)
    result = "thu";
  cout << result << endl;
}


Error: 0

Fixed submission:

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string day[7] = {"fri", "sat", "sun", "mon", "tue", "wed", "thu"};
  ll a;
  cin >> a;
  a %= 7;
  cout << day[a - 1] << endl;
}
Problem p00354 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  string date[7] = {"thu", "fri", "sat", "sun", "mon", "tue", "wed"};

  int X;
  cin >> X;

  cout << date[X % 7] << endl;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  string date[7] = {"fri", "sat", "sun", "mon", "tue", "wed", "thu"};

  int X;
  cin >> X;

  cout << date[X % 7 - 1] << endl;
}
Problem p00355 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b, n, s, f, i = 0;
  cin >> a >> b >> n;
  while (1) {
    cin >> s >> f;
    if ((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)) {
      cout << '1' << endl;
      break;
    }
    if (++i >= n) {
      cout << '0' << endl;
      break;
    }
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, n, s, f, i = 0;
  cin >> a >> b >> n;
  while (1) {
    cin >> s >> f;
    if ((a >= s && b <= f) || (s > a && s < b) || (f > a && f < b)) {
      cout << '1' << endl;
      break;
    }
    if (++i == n) {
      cout << '0' << endl;
      break;
    }
  }
}
Problem p00355 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define loop(times) for (int i = 0; i < times; i++)
using namespace std;

int main() {
  int a, b, N, t = 1;
  cin >> a >> b >> N;

  int s[N], f[N];
  int p[1001];
  int c[1001];

  loop(1000) p[i] = 0, c[i] = 0;

  loop(N) {
    cin >> s[i] >> f[i];
    p[s[i]] += 1;
    p[f[i]] -= 1;
  }
  p[a] += 1;
  p[b] -= 1;
  if (c[0] == 2) {
    cout << 1 << endl;
    t = 0;
  }
  loop(1000) {
    c[i + 1] = c[i] + p[i];
    if (c[i + 1] == 2) {
      cout << 1 << endl;
      t = 0;
      break;
    }
  }
  if (t == 1)
    cout << 0 << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define loop(times) for (int i = 0; i < (times); i++)

using namespace std;

int main() {
  bool t = 1;
  while (t) {
    int a, b, N;

    cin >> a >> b >> N;
    int s[N];
    int f[N];
    int p[1001];
    int c[1001];
    loop(1000) p[i] = 0, c[i] = 0;

    loop(N) {
      cin >> s[i] >> f[i];
      p[s[i] - 1] += 1;
      p[f[i] - 1] += -1;
    }

    loop(1000) c[i + 1] = c[i] + p[i];
    loop(b - a + 1) c[a + i] += 1;
    loop(1000 - b) c[b + i] -= 1;
    loop(1000) {
      if (c[i] == 2) {
        cout << 1 << endl;
        t = 0;
        break;
      }
    }
    if (t == 1) {
      cout << 0 << endl;
      t = 0;
    }
  }
}