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

#include <bits/stdc++.h>
using namespace std;
#define int long long
int answer = 1e9;
int c[40];
vector<int> g[40];
int n, m;
vector<int> route;
int done[40];
int wf[40][40];

int tl = 10000000;

void dfs(int x, int bit, int cost) {

  if (done[x])
    return;
  int nextBit = bit;
  int diff = 0;
  if (!(bit >> x & 1)) {
    diff += c[x];
    nextBit |= (1ll << x);
  }

  for (auto i : g[x]) {
    if (!(bit >> i & 1)) {

      nextBit |= (1ll << i);
      diff += c[i];
    }
  }
  int nextCost = cost + diff;
  if (nextCost >= answer) {
    return;
  }
  if (x == n - 1) {
    answer = nextCost;
    return;
  }
  tl--;
  if (tl <= 0)
    return;
  done[x] = 1;
  route.push_back(x);
  // cout << "(" << nextBit << ")" << nextCost << " = ";
  // for( auto i : route) cout << i << " ";
  // cout << endl;

  random_shuffle(g[x].begin(), g[x].end());
  for (auto i : g[x]) {
    if ((bit >> i & 1) == 0)
      dfs(i, nextBit, nextCost);
  }
  route.pop_back();
  done[x] = 0;
}

signed main() {
  for (int i = 0; i < 40; i++)
    for (int j = 0; j < 40; j++)
      wf[i][j] = i == j ? 0 : 1e9;

  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
    // wf[a][b] = a;
    // wf[b][a] = b;
  }
  dfs(0, 0, 0);
  cout << answer << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int answer = 1e9;
int c[40];
vector<int> g[40];
int n, m;
vector<int> route;
int done[40];
int wf[40][40];

int tl = 100000000;

void dfs(int x, int bit, int cost) {
  if (done[x])
    return;
  int nextBit = bit;
  int diff = 0;
  if (!(bit >> x & 1)) {
    diff += c[x];
    nextBit |= (1ll << x);
  }

  for (auto i : g[x]) {
    if (!(bit >> i & 1)) {

      nextBit |= (1ll << i);
      diff += c[i];
    }
  }
  int nextCost = cost + diff;
  if (nextCost >= answer) {
    return;
  }
  if (x == n - 1) {
    answer = nextCost;
    return;
  }
  tl--;
  if (tl <= 0)
    return;
  done[x] = 1;
  route.push_back(x);
  // cout << "(" << nextBit << ")" << nextCost << " = ";
  // for( auto i : route) cout << i << " ";
  // cout << endl;

  for (auto i : g[x]) {
    if (count(route.begin(), route.begin() + route.size() - 1, i))
      continue;
    dfs(i, nextBit, nextCost);
  }
  route.pop_back();
  done[x] = 0;
}

signed main() {
  for (int i = 0; i < 40; i++)
    for (int j = 0; j < 40; j++)
      wf[i][j] = i == j ? 0 : 1e9;

  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
    // wf[a][b] = a;
    // wf[b][a] = b;
  }
  dfs(0, 0, 0);
  cout << answer << endl;
}
Problem p00943 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int t, head[50], w[50];

struct edges {
  int to, next;
} e[(50 * 50) << 1];

void add(int x, int y) {
  e[++t] = (edges){y, head[x]};
  head[x] = t;
}

int n, m, ans = 1000000, now;
int vis[50], step;
void dfs(int x) {
  step++;
  // cout<<x<<' '<<step<<endl;
  if (x == n) {
    for (int p = head[x]; p; p = e[p].next)
      if (!vis[e[p].to])
        now += w[e[p].to];
    ans = min(ans, now);
    for (int p = head[x]; p; p = e[p].next)
      if (!vis[e[p].to])
        now -= w[e[p].to];
    step--;
    // printf("vis[2]=%d\\n",vis[2]);
    return;
  }
  for (int p = head[x]; p; p = e[p].next)
    if (!vis[e[p].to]) {
      vis[e[p].to] = step;
      now += w[e[p].to];
    }
  for (int p = head[x]; p; p = e[p].next)
    if (vis[e[p].to] == step) {

      dfs(e[p].to);
      // printf("**step=%d  next(%d)=%d
      // vis[]=%d\\n",step,x,e[e[p].next].to,vis[e[e[p].next].to]);
    }
  for (int p = head[x]; p; p = e[p].next)
    if (vis[e[p].to] == step) {
      vis[e[p].to] = 0;
      now -= w[e[p].to];
    }
  step--;
  // cout<<step<<endl;
}
int main() {
  int x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    scanf("%d", &w[i]);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  now = w[1];
  vis[1] = 1;
  dfs(1);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#define N 45
using namespace std;

struct edge {
  int to, next;
} e[N * N];
int n, m, cnt, ans;
int head[N], w[N], pr[N], vis[N];

void add(int x, int y) {
  e[++cnt].next = head[x], e[cnt].to = y;
  head[x] = cnt;
}

bool mark[N];

void calc(int sp) {
  memset(mark, 0, sizeof(mark));
  int x = sp, minn = w[sp];
  mark[sp] = 1;
  while (x != 0) {
    for (int j = head[x]; j; j = e[j].next)
      if (!mark[e[j].to])
        minn += w[e[j].to], mark[e[j].to] = 1;
    x = pr[x];
  }
  if (minn < ans)
    ans = minn;
}

void dfs(int x) {
  if (x == n) {
    calc(n);
    return;
  }
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (!vis[y]) {
      vis[y] = 1;
      pr[y] = x;
      dfs(y);
      vis[y] = 0;
    }
  }
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &w[i]);
  for (int i = 1, x, y; i <= m; ++i) {
    scanf("%d %d", &x, &y);
    add(x, y), add(y, x);
  }
  memset(vis, 0, sizeof(vis));
  pr[1] = 0;
  ans = 2e9;
  vis[1] = 1;
  dfs(1);
  printf("%d\\n", ans);
  return 0;
}
Problem p00943 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
int val[45];
LL use[45];
vector<int> s[45];
int ans = 1 << 30;
int n, m;
int cnt(LL mask) {
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    if (mask & (1LL << i))
      tmp += val[i];
  }
  return tmp;
}
LL is = 0;
void dfs(int u, int fa, LL mask) {
  if (is & (use[u] ^ (1LL << fa) ^ (1LL << u)))
    return;
  if (u == n - 1) {
    ans = min(ans, cnt(mask));
    return;
  }
  for (int i = 0; i < s[u].size(); i++) {
    int v = s[u][i];
    if (is & (1LL << v))
      continue;
    is ^= (1LL << v);
    dfs(v, u, mask | use[v]);
    is ^= (1LL << v);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &val[i]);
    use[i] = (1LL << i);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    s[x].push_back(y);
    s[y].push_back(x);
    use[x] |= (1LL << y);
    use[y] |= (1LL << x);
  }
  is = 1;
  dfs(0, n, use[0]);
  printf("%d\\n", ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
int val[45];
LL use[45];
vector<int> s[45];
int ans = 1 << 30;
int n, m;
int is[45];
int cnt(LL mask) {
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    if (mask & (1LL << i))
      tmp += val[i];
  }
  return tmp;
}
void dfs(int u, LL mask) {
  if (u == n - 1) {
    ans = min(ans, cnt(mask));
    return;
  }
  for (int i = 0; i < s[u].size(); i++) {
    int v = s[u][i];
    if (is[v])
      continue;
    is[v] = 1;
    dfs(v, mask | use[v]);
    is[v] = 0;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &val[i]);
    use[i] = (1LL << i);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    s[x].push_back(y);
    s[y].push_back(x);
    use[x] |= (1LL << y);
    use[y] |= (1LL << x);
  }
  is[0] = 1;
  dfs(0, use[0]);
  printf("%d\\n", ans);
}
Problem p00943 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 50;
struct State {
  LL S;
  int cur, val;
  State(LL _S = 0, int _cur = 0, int _val = 0) : S(_S), cur(_cur), val(_val) {}
  bool operator<(const State &rh) const { return val > rh.val; }
};
map<LL, int> Dist[maxn]; // Dist[cur][state]
int n, m;
int V[maxn];
LL G[maxn];
vector<int> E[maxn];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> V[i];
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    G[u] |= 1LL << v;
    E[u].push_back(v);
    G[v] |= 1LL << u;
    E[v].push_back(u);
  }
  int Init = 0;
  for (int i = 1; i <= n; i++) {
    G[i] |= 1LL << i;
    if (G[1] & (1LL << i))
      Init += V[i];
  }
  priority_queue<State> Q;
  Q.push(State(G[1], 1, Init));
  Dist[1][G[1]] = Init;
  while (!Q.empty()) {
    State now = Q.top();
    Q.pop();
    int u = now.cur;
    if (u == n) {
      cout << now.val << endl;
      break;
    }
    for (int i = 0; i < (int)E[u].size(); i++) {
      int v = E[u][i];
      LL newS = now.S | G[v];
      int newVal = 0;
      for (int j = 1; j <= n; j++)
        if (newS & (1LL << j))
          newVal += V[j];
      if (Dist[v].find(newS) == Dist[v].end() || Dist[v][newS] > newVal) {
        Dist[v][newS] = newVal;
        Q.push(State(newS, v, newVal));
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 50;
int used[maxn], c[maxn], cn[maxn], n, m, s, t, ans = maxn * 200;
vector<int> G[50];
inline void add_edge(int f, int t) {
  G[f].push_back(t);
  G[t].push_back(f);
}
int dfs(int x, int cnt) {
  used[x] = 1;
  int sum = 0;
  for (int i = 0; i < G[x].size(); i++)
    if (!used[G[x][i]] && cn[G[x][i]] == -1)
      sum += c[G[x][i]], cn[G[x][i]] = x;
  if (x == n || cnt >= ans) {
    ans = min(ans, cnt + sum);
    used[x] = 0;
    for (int i = 1; i <= n; i++)
      cn[i] = (cn[i] == x ? -1 : cn[i]);
    return 0;
  }
  for (int i = 0; i < G[x].size(); i++) {
    int gt = G[x][i];
    if (!used[gt])
      dfs(gt, cnt + sum);
  }
  used[x] = 0;
  for (int i = 1; i <= n; i++)
    cn[i] = (cn[i] == x ? -1 : cn[i]);
}
int main() {
  memset(cn, -1, sizeof(cn));
  for (int i = 0; i < 50; i++)
    G[i].resize(50);
  scanf("%d%d", &n, &m), s = 1, t = n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &c[i]);
  for (int i = 1, a, b; i <= m; i++) {
    scanf("%d%d", &a, &b);
    add_edge(a, b);
  }
  cn[1] = 0;
  dfs(s, c[s]);
  printf("%d\\n", ans);
  return 0;
}
Problem p00946 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int N, M; //?度? n 的序列,有 m 个操作
int F[205000];
bool Jud[205000];

int main() {
  cin >> N >> M;
  memset(Jud, true, sizeof(Jud));
  for (int i = 1; i <= M; i++)
    cin >> F[i];
  for (int i = M; i >= 1; i--)
    if (Jud[F[i]] == true) {
      Jud[F[i]] = false;
      cout << F[i] << endl;
    }
  for (int i = 1; i <= N; i++)
    if (Jud[i] == true)
      cout << i << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int N, M; //?度? n 的序列,有 m 个操作
int F[20500];
bool Jud[20500];

int main() {
  cin >> N >> M;
  memset(Jud, true, sizeof(Jud));
  for (int i = 1; i <= M; i++)
    cin >> F[i];
  for (int i = M; i >= 1; i--)
    if (Jud[F[i]] == true) {
      Jud[F[i]] = false;
      cout << F[i] << endl;
    }
  for (int i = 1; i <= N; i++)
    if (Jud[i] == true)
      cout << i << endl;
  return 0;
}
Problem p00946 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(int argc, char **argv) {
  int nLength, nRequests;

  cin >> nLength >> nRequests;

  vector<int> tmpRequests;
  tmpRequests.reserve(nRequests);

  for (int i = 0; i < nRequests; i++) {
    int query;
    cin >> query;
    tmpRequests.push_back(query);
  }

  vector<int> requestVec;
  set<int> requestSet;

  requestVec.reserve(nRequests);

  for (int i = 0; i < nRequests; i++) {
    int query = tmpRequests[nRequests - 1 - i];

    if (requestSet.find(query) == requestSet.end()) {
      requestVec.push_back(query);
      requestSet.insert(query);
    }
  }

  for (int i = 0; i < requestVec.size(); i++)
    cout << requestVec[i] << endl;

  for (int i = 1; i <= nLength; i++) {
    if (requestSet.find(i) == requestSet.end())
      cout << i << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char **argv) {
  int nLength, nRequests;

  cin >> nLength >> nRequests;

  int *arry = new int[nLength];
  for (int i = 0; i < nLength; i++)
    arry[i] = i + 1;

  int *tmp = new int[nLength];

  for (int i = 0; i < nRequests; i++) {
    int query;
    cin >> query;

    for (int j = 0; j < nLength; j++) {
      if (arry[j] == query) {
        for (int k = 0; k < j; k++)
          tmp[k] = arry[k];

        for (int k = j + 1; k < nLength; k++)
          tmp[k - 1] = arry[k];

        arry[0] = query;

        for (int k = 0; k < nLength - 1; k++)
          arry[k + 1] = tmp[k];
      }
    }
  }

  for (int i = 0; i < nLength; i++)
    cout << arry[i] << endl;

  delete[] arry;
  delete[] tmp;

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n + 1, 0);
  vector<int> ans(m);

  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    ans[i] = a;
    used[a] = 1;
  }

  vector<int> syu(n + 1, 0);

  for (int i = 0; i < m; i++) {
    if (syu[ans[m - i - 1]] != 1) {
      cout << ans[m - i - 1] << endl;
      syu[ans[m - i - 1]] = 1;
    }
  }

  for (int i = 1; i < n + 1; i++) {
    if (used[i] == 0)
      cout << i << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n + 1, 0);
  vector<int> ans(m);

  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    ans[i] = a;
    used[a] = 1;
  }

  vector<int> syu(m + 1, 0);

  for (int i = 0; i < m; i++) {
    if (syu[ans[m - i - 1]] != 1) {
      cout << ans[m - i - 1] << endl;
      syu[ans[m - i - 1]] = 1;
    }
  }

  for (int i = 1; i < n + 1; i++) {
    if (used[i] == 0)
      cout << i << endl;
  }

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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) begin(x), end(x)
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
int main() {
  int N, M;
  cin >> N >> M;

  vector<int> e(M);
  for (auto &x : e) {
    cin >> x;
  }

  reverse(ALL(e));

  vector<int> vc, flag(N + 1, 0);
  REP(i, M) // O(n)
  {
    if (flag[e[i]] == 0) // O(1)
    {
      vc.emplace_back(e[i]); // O(1)
      flag[e[i]] = 1;
    }
  }

  // move
  for (const auto &x : vc) {
    cout << x << endl;
  }

  sort(ALL(vc));

  // not move
  REP2(i, 1, N + 1) // O(n)
  {
    if (flag[i] != 0) // O(1)
    {
      continue;
    }
    cout << i << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) begin(x), end(x)
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
int main() {
  int N, M;
  cin >> N >> M;

  vector<int> e(M);
  for (auto &x : e) {
    cin >> x;
  }

  reverse(ALL(e));

  //???????????????????????????vector?????\\??????
  vector<int> vc;
  REP(i, M) // O(n)
  {
    if (count(ALL(vc), e[i]) <
        1) // size() ?????????????????°?????? <- O(log n) ???
    {
      vc.emplace_back(e[i]); //?????´?????°??????
    }
  }

  //?§?????????????
  for (const auto &x : vc) {
    cout << x << endl;
  }

  sort(ALL(vc));

  //?§????????????????
  REP2(i, 1, N) // O(n)
  {
    if (count(ALL(vc), i) == 1) // size() ?????????????????°??????
    {
      continue;
    }
    cout << i << endl;
  }

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

#include <cstdio>
#include <iostream>
#include <memory.h>
using namespace std;
bool vis[200005];
bool vis1[200005];
int a[200005];
int main() {
  memset(vis, 0, sizeof(vis));
  memset(vis1, 0, sizeof(vis1));
  int n, m;
  scanf("%d%d", &n, &m);
  int j = 0;
  for (int i = 0; i < m; i++) {
    int b;
    scanf("%d", &b);
    vis[b] = 1;
    a[j++] = b;
  }
  while (j--) {
    if (vis1[a[j]] == 0) {
      printf("%d\\n", a[j]);
      vis1[a[j]] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0)
      printf("%d\\n", i);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int n, m, e;
bool moved[200010];
int pre[200010];
int nex[200010];
int main() {
  ios::sync_with_stdio(false);

  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) {
      moved[i] = 0;
      nex[i] = -1;
      pre[i] = -1;
    }
    int fir = -1, tmp_pre = -1;
    for (int i = 1; i <= m; i++) {
      cin >> e;
      if (!moved[i]) {
        if (tmp_pre == -1) {
          moved[e] = 1;
          tmp_pre = e;
          fir = e;
        } else {
          moved[e] = 1;
          pre[e] = tmp_pre;
          nex[e] = -1;
          nex[tmp_pre] = e;
          tmp_pre = e;
        }
      } else {
        nex[pre[e]] = nex[e];
        pre[nex[e]] = pre[e];
        pre[e] = tmp_pre;
        nex[e] = -1;
        nex[tmp_pre] = e;
        tmp_pre = e;
      }
    }
    while (tmp_pre != -1) {
      cout << tmp_pre << endl;
      tmp_pre = pre[tmp_pre];
    }
    for (int i = 1; i <= n; i++) {
      if (!moved[i])
        cout << i << endl;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;
const int maxn = 200050;
int a[maxn];
int next[maxn], last[maxn];
int main() {
  int n, m;
  int x;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    next[i] = i + 1;
    last[i] = i - 1;
  }
  last[n] = n - 1;
  int head = 1;
  int num = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x); // num;
    if (last[x] == 0)
      continue;
    if (next[x] == 0) {
      next[last[x]] = next[x];
      next[x] = head;
      last[head] = x;
      last[x] = 0;
      head = x;
      continue;
    }
    next[last[x]] = next[x];
    last[next[x]] = last[x];
    next[x] = head;
    last[head] = x;
    last[x] = 0;
    head = x;
  }
  // for(int i=1;i<=n;i++)cout<<next[i]<<endl;
  for (int i = head; i; i = next[i])
    printf("%d\\n", i);
  return 0;
}

Error: 0

Fixed submission:

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

const int maxn = 200000 + 5;

int a[maxn];
bool vis[maxn];

int main() {
  int n, m, tot = 0;
  scanf("%d%d", &n, &m);
  for (int i = n; i; i--)
    a[++tot] = i;
  for (int i = m; i > 0; i--) {
    int z;
    scanf("%d", &z);
    a[++tot] = z;
  }
  for (int i = tot; i; i--)
    if (!vis[a[i]])
      printf("%d\\n", a[i]), vis[a[i]] = 1;
  return 0;
}
Problem p00946 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 40
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n, m;
vector<int> ans;
bool saw[200001];

int main() {
  cin >> n >> m;
  rep(i, m) {
    int x;
    cin >> x;
    ans.push_back(x);
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    if (saw[ans[i]])
      continue;
    cout << ans[i] << endl;
    saw[ans[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (saw[i])
      continue;
    cout << i << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 40
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n, m;
vector<int> ans;
bool saw[100001];

int main() {
  cin >> n >> m;
  rep(i, m) {
    int x;
    cin >> x;
    ans.push_back(x);
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    if (saw[ans[i]])
      continue;
    cout << ans[i] << endl;
    saw[ans[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (saw[i])
      continue;
    cout << i << endl;
  }
}
Problem p00946 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <list>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int n;
  int m;
  scanf("%d %d", &n, &m);
  bitset<200001> b;
  list<int> v;
  for (int i = 0; i < m; ++i) {
    int e;
    scanf("%d", &e);
    v.push_front(e);
  }

  for (auto &&i : v) {
    if (b[i]) {
    } else {
      printf("%d\\n", i);
      b[i] = true;
    }
  }
  for (auto i = 1; i <= n; ++i) {
    if (!b[i]) {
      printf("%d\\n", i);
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <list>
#include <vector>

using namespace std;

int main() {
  int n;
  int m;
  scanf("%d %d", &n, &m);
  bitset<2000001> b;
  list<int> v;
  // v.reserve(100000);
  for (int i = 0; i < m; ++i) {
    int e;
    scanf("%d", &e);
    if (b[e]) {
      auto it = find(begin(v), end(v), e);
      if (it != end(v)) {
        v.erase(it);
        v.push_front(e);
      }
    } else {
      b[e] = true;
      v.push_front(e);
    }
  }

  for (auto &&i : v) {
    printf("%d\\n", i);
  }
  for (auto i = 1; i < n; ++i) {
    if (!b[i]) {
      printf("%d\\n", i);
    }
  }
}
Problem p00946 (C++) — buggy submission, verdict: Runtime Error

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

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define fi first
#define se second

#define INF 2147483600

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(m);
  rep(i, m) scanf("%d", &vec[i]);

  vector<bool> used(n + 1, false);
  for (int i = m - 1; i >= 0; i--) {
    if (!used[vec[i]])
      printf("%d\\n", vec[i]);
    used[vec[i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      printf("%d\\n", i);
    }

  return 0;
}

Error: 0

Fixed submission:

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

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define fi first
#define se second

#define INF 2147483600

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);
  rep(i, m) scanf("%d", &vec[i]);

  vector<bool> used(n + 1, false);
  for (int i = m - 1; i >= 0; i--) {
    if (!used[vec[i]])
      printf("%d\\n", vec[i]);
    used[vec[i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      printf("%d\\n", i);
    }

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

#include <iostream>
using namespace std;

int n, m;
int e[200000];

int main() {
  int i;

  cin >> n >> m;
  for (i = 0; i < m; i++)
    cin >> e[i];

  static bool used[200001] = {false};
  for (i = m - 1; i >= 0; i--) {
    if (!used[e[i]]) {
      used[e[i]] = true;
      cout << e[i] << endl;
    }
  }
  for (i = 1; i <= n; i++) {
    if (!used[i])
      cout << i << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int n, m;
int e[200000];

int main() {
  int i;

  cin >> n >> m;
  for (i = 0; i < m; i++)
    cin >> e[i];

  bool used[100001] = {false};
  for (i = m - 1; i >= 0; i--) {
    if (!used[e[i]]) {
      used[e[i]] = true;
      cout << e[i] << endl;
    }
  }
  for (i = 1; i <= n; i++) {
    if (!used[i])
      cout << i << endl;
  }
  return 0;
}