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

#include <iostream>
using namespace std;

int n, m, c[300];

void Lsh() {
  int b1[300], b2[300];
  for (int i = 1; i <= n; i++) {
    b1[i] = c[i];
    b2[i] = c[n + i];
  }
  for (int i = 1; i <= n; i++) {
    c[2 * i - 1] = b1[i];
    c[2 * i] = b2[i];
  }
}

void Kcut(int k) {
  int b1[300], b2[300];
  for (int i = 1; i <= k; i++)
    b1[i] = c[i];
  for (int i = 1; i <= 2 * n - k; i++)
    b2[i] = c[i + k];

  for (int i = 1; i <= 2 * n - k; i++)
    c[i] = b2[i];
  for (int i = 1; i <= k; i++)
    c[i + 2 * n - k] = b1[i];
}

int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++)
    c[i] = i;
  for (int i = 0; i < m; i++) {
    int com;
    cin >> com;
    if (com == 0)
      Lsh();
    else
      Kcut(com);
  }
  for (int i = 1; i <= 2 * n; i++)
    cout << c[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int n, m, c[201];

void Lsh() {
  int b1[101], b2[101];
  for (int i = 1; i <= n; i++) {
    b1[i] = c[i];
    b2[i] = c[n + i];
  }
  for (int i = 1; i <= n; i++) {
    c[2 * i - 1] = b1[i];
    c[2 * i] = b2[i];
  }
}

void Kcut(int k) {
  int b1[101], b2[101];
  for (int i = 1; i <= k; i++)
    b1[i] = c[i];
  for (int i = 1; i <= 2 * n - k; i++)
    b2[i] = c[i + k];

  for (int i = 1; i <= 2 * n - k; i++)
    c[i] = b2[i];
  for (int i = 1; i <= k; i++)
    c[i + 2 * n - k] = b1[i];
}

int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++)
    c[i] = i;
  for (int i = 0; i < m; i++) {
    int com;
    cin >> com;
    if (com == 0)
      Lsh();
    else
      Kcut(com);
  }
  for (int i = 1; i <= 2 * n; i++)
    cout << c[i] << endl;
  return 0;
}
Problem p00436 (C++) — buggy submission, verdict: Runtime Error

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

typedef list<int> li;

int main(void) {
  int n, m;
  cin >> n;
  std::vector<int> v;
  for (int i = 1; i <= 2 * n; i++)
    v.push_back(i);
  cin >> m;
  while (m--) {
    int k;
    cin >> k;
    if (k == 0) {
      // ref
      std::vector<int> v1(n);
      std::vector<int> v2(n);
      copy(v.begin(), v.begin() + n, v1.begin());
      copy(v.begin() + n, v.end(), v2.begin());
      for (int i = 0; i < 2 * n; i++) {
        if (i % 2 == 0)
          v[i] = v1[i / 2];
        else
          v[i] = v2[i / 2];
      }
    } else {
      // cut
      std::vector<int> v1(k);
      std::vector<int> v2(2 * n - k);
      copy(v.begin(), v.begin() + k, v1.begin());
      copy(v.begin() + k, v.end(), v2.begin());
      for (int i = 0; i < v2.size(); i++) {
        v[i] = v2[i];
      }
      for (int i = 0; i < v1.size(); i++) {
        v[i + v2.size()] = v1[i];
      }
    }
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

typedef list<int> li;

int main(void) {
  int n, m;
  cin >> n;
  std::vector<int> v;
  for (int i = 1; i <= 2 * n; i++)
    v.push_back(i);
  cin >> m;
  while (m--) {
    int k;
    cin >> k;
    if (k == 0) {
      // ref
      std::vector<int> v1(n);
      std::vector<int> v2(n);
      copy(v.begin(), v.begin() + n, v1.begin());
      copy(v.begin() + n, v.end(), v2.begin());
      for (int i = 0; i < 2 * n; i++) {
        if (i % 2 == 0)
          v[i] = v1[i / 2];
        else
          v[i] = v2[i / 2];
      }
    } else {
      // cut
      std::vector<int> v1(k);
      std::vector<int> v2(n - k);
      copy(v.begin(), v.begin() + k, v1.begin());
      copy(v.begin() + k, v.end(), v2.begin());
      for (int i = 0; i < k; i++) {
        v[i] = v1[i];
      }
      for (int i = k; i < 2 * n; i++) {
        v[i] = v2[i - k];
      }
    }
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << endl;
  }
  return 0;
}
Problem p00436 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {

  int a, m, n;
  int i, j, k;
  int arr[300];
  int arr2[300];

  cin >> a;

  for (i = 0; i < 2 * a; i++)
    arr[i] = i + 1;

  cin >> m;
  for (i = 0; i < m; i++) {

    cin >> n;

    if (n == 0) {

      for (j = 0; j < a; j++) {

        arr2[j * 2] = arr[j];
        arr2[j * 2 + 1] = arr[j + a];
      }

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];

    }

    else {

      for (j = n, k = 0; j < 2 * a; j++, k++)
        arr2[k] = arr[j];
      for (j = 0; j < n; j++, k++)
        arr2[k] = arr[j];

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];
    }
  }

  for (i = 0; i < 2 * a; i++)
    cout << arr[i] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int a, m, n;
  int i, j, k;
  int arr[100];
  int arr2[100];

  cin >> a;

  for (i = 0; i < 2 * a; i++)
    arr[i] = i + 1;

  cin >> m;
  for (i = 0; i < m; i++) {

    cin >> n;

    if (n == 0) {

      for (j = 0; j < a; j++) {

        arr2[j * 2] = arr[j];
        arr2[j * 2 + 1] = arr[j + a];
      }

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];

    }

    else {

      for (j = n, k = 0; j < 2 * a; j++, k++)
        arr2[k] = arr[j];
      for (j = 0; j < n; j++, k++)
        arr2[k] = arr[j];

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];
    }
  }

  for (i = 0; i < 2 * a; i++)
    cout << arr[i] << endl;

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

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

int main() {
  int a;
  cin >> a;
  vector<int> s(a * 2);
  for (int x = 0; x < a * 2; x++) {
    s[x] = x + 1;
  }
  int b;
  cin >> b;
  for (int c = 0; c < b; c++) {
    int d;
    cin >> d;
    vector<int> e(a * 2);
    for (int f = 0; f < a * 2; f++) {
      e[f] = s[f];
    }
    if (d == 0) {
      for (int g = 0; g < a * 2; g++) {
        if (g % 2 == 0) {
          s[g] = e[g / 2];
        } else {
          s[g] = e[a + (g - 1) / 2];
        }
      }
    } else {
      for (int i = 0; i < 2 * a - d; i++) {
        s[i] = e[d + i];
      }
      for (int i = 0; i < d; i++) {
        s[i + (2 * a - d)] = e[i];
      }
    }
  }
  for (int q : s) {
    cout << q << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    cin;
    if (cin.fail())
      break;
  }
}
Problem p00436 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int i, c, way, n, m, mt[200];

  scanf("%d%d", &n, &m);
  for (i = 0; n * 2 > i; i++)
    mt[i] = i + 1;
  for (i = 0; m > i; i++) {
    int mta[199], mtb[199];
    scanf("%d", &way);
    if (!way) {

      memcpy(mta, mt, sizeof(int) * n);
      memcpy(mtb, &mt[n], sizeof(int) * n);
      for (c = 0; n > c; c++) {
        mt[(c * 2)] = mta[c];
        mt[(c * 2) + 1] = mtb[c];
      }
    } else {
      memcpy(mta, mt, sizeof(int) * way);
      memcpy(mtb, &mt[way], sizeof(int) * (n * 2 - way));
      memcpy(mt, mtb, sizeof(int) * (n * 2 - way));
      memcpy(&mt[n * 2 - way], mta, sizeof(int) * way);

      /*	for (c = 0; n * 2 - way > c; c++){
                      mt[c] = mtb[c];
              }
              for (c = 0; way > c; c++){
                      mt[c + (n * 2 - way)] = mta[c];
              }*/
    }
  }
  for (i = 0; n * 2 > i; i++) {
    printf("%d\\n", mt[i]);
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  int i, c, way, n, m, mt[201];

  scanf("%d%d", &n, &m);
  for (i = 0; n * 2 > i; i++)
    mt[i] = i + 1;
  for (i = 0; m > i; i++) {
    int mta[100], mtb[100];
    scanf("%d", &way);
    if (!way) {

      memcpy(mta, mt, sizeof(int) * n);
      memcpy(mtb, &mt[n], sizeof(int) * n);
      for (c = 0; n > c; c++) {
        mt[(c * 2)] = mta[c];
        mt[(c * 2) + 1] = mtb[c];
      }
    } else {
      memcpy(mta, mt, sizeof(int) * way);
      memcpy(mtb, &mt[way], sizeof(int) * (n * 2 - way));
      memcpy(mt, mtb, sizeof(int) * (n * 2 - way));
      memcpy(&mt[n * 2 - way], mta, sizeof(int) * way);
    }
  }

  for (i = 0; n * 2 > i; i++) {
    printf("%d\\n", mt[i]);
  }

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

void riful(int[], int);
void cut(int[], int, int);

int main() {
  int n, m, i;
  int card[200];
  for (i = 0; i < 200; i++) {
    card[i] = -1;
  }
  cin >> n >> m;
  for (i = 0; i < 200; i++) {
    if (i < n * 2)
      card[i] = i;
    else
      card[i] = -1;
  }
  for (i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (k == 0)
      riful(card, n);
    else
      cut(card, n, k);
  }
  for (i = 0; i < n * 2; i++) {
    printf("%d\\n", card[i] + 1);
  }
  return 0;
}

void riful(int card[], int n) {
  int A[100], B[100], i;
  for (i = 0; i < 100; i++) {
    A[i] = B[i] = -1;
  }
  for (i = 0; i < n; i++) {
    A[i] = card[i];
    B[i] = card[n + i];
  }
  for (i = 0; i < n; i++) {
    card[i * 2] = A[i];
    card[i * 2 + 1] = B[i];
  }
}

void cut(int card[], int n, int k) {
  int A[200], B[200], i;
  for (i = 0; i < n * 2; i++) {
    if (i < k)
      A[i] = card[i];
    else
      B[i - k] = card[i];
  }
  for (i = 0; i < n * 2; i++) {
    if (i < n * 2 - k)
      card[i] = B[i];
    else
      card[i] = A[i - (n * 2 - k)];
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

void riful(int[], int);
void cut(int[], int, int);

int main() {
  int n, m, i;
  int card[200];
  for (i = 0; i < 200; i++) {
    card[i] = -1;
  }
  cin >> n >> m;
  for (i = 0; i < 200; i++) {
    if (i < n * 2)
      card[i] = i;
    else
      card[i] = -1;
  }
  for (i = 0; i < m + 1; i++) {
    int k;
    cin >> k;
    if (k == 0)
      riful(card, n);
    else
      cut(card, n, k);
  }
  for (i = 0; i < n * 2; i++) {
    printf("%d\\n", card[i] + 1);
  }
  return 0;
}

void riful(int card[], int n) {
  int A[100], B[100], i;
  for (i = 0; i < 100; i++) {
    A[i] = B[i] = -1;
  }
  for (i = 0; i < n; i++) {
    A[i] = card[i];
    B[i] = card[n + i];
  }
  for (i = 0; i < n; i++) {
    card[i * 2] = A[i];
    card[i * 2] = B[i];
  }
}

void cut(int card[], int n, int k) {
  int A[100], B[100], i;
  for (i = 0; i < n * 2; i++) {
    if (i < k)
      A[i] = card[i];
    else
      B[i - k] = card[i];
  }
  for (i = 0; i < n * 2; i++) {
    if (i < n * 2 - k)
      card[i] = B[i];
    else
      card[i] = A[i - (n * 2 - k)];
  }
}
Problem p00436 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> v(2 * n);
  rep(i, 2 * n) v[i] = i + 1;

  rep(i, m) {
    int k;
    cin >> k;

    vector<int> a, b;

    if (k == 0) {
      rep(j, n) {
        a.push_back(v[j]);
        a.push_back(v[j + n]);
      }

      v.clear();
      copy(a.begin(), a.end(), back_inserter(v));
    } else {
      rep(j, k) { a.push_back(v[j]); }

      REP(j, k, 2 * n) { b.push_back(v[j]); }

      v.clear();
      copy(b.begin(), b.end(), back_inserter(v));
      copy(a.begin(), a.end(), back_inserter(v));
    }
  }

  rep(i, 2 * n) { cout << v[i] << endl; }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> v(n);
  rep(i, 2 * n) v[i] = i + 1;

  rep(i, m) {
    int k;
    cin >> k;

    vector<int> a, b;

    if (k == 0) {
      rep(j, n) {
        a.push_back(v[j]);
        a.push_back(v[j + n]);
      }

      v.clear();
      copy(a.begin(), a.end(), back_inserter(v));
    } else {
      rep(j, k) { a.push_back(v[j]); }

      REP(j, k, 2 * n) { b.push_back(v[j]); }

      v.clear();
      copy(b.begin(), b.end(), back_inserter(v));
      copy(a.begin(), a.end(), back_inserter(v));
    }
  }

  rep(i, 2 * n) { cout << v[i] << endl; }

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


#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int arr[2 * 100 + 2];
int arr_2[2 * 100 + 2];

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

  for (int i = 1; i <= 2 * N; i++)
    arr[i] = i;
  int m;
  cin >> m;
  while (m--) {
    int oper;
    cin >> oper;
    // if(oper==0) break;
    if (oper == 0) {
      int count = 1;
      for (int i = 1; i <= N; i++) {
        arr_2[count++] = arr[i];
        arr_2[count++] = arr[i + N];
      }
      for (int i = 1; i <= 2 * N; i++)
        arr[i] = arr_2[i];
    } else {
      for (int i = 1 + oper; i <= 2 * N; i++)
        arr_2[i - oper] = arr[i];
      for (int i = 1; i <= oper; i++)
        arr_2[2 * N - oper + i] = arr[i];
      for (int i = 1; i <= 2 * N; i++)
        arr[i] = arr_2[i];
    }
  }
  for (int i = 1; i <= 2 * N; i++)
    cout << arr[i] << endl;

  // while(1);
  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int arr[2 * 100 + 2];
int arr_2[2 * 100 + 2];

int main() {
  int N;
  while (cin >> N) {
    for (int i = 1; i <= 2 * N; i++)
      arr[i] = i;
    int m;
    cin >> m;
    while (m--) {
      int oper;
      cin >> oper;
      // if(oper==0) break;
      if (oper == 0) {
        int count = 1;
        for (int i = 1; i <= N; i++) {
          arr_2[count++] = arr[i];
          arr_2[count++] = arr[i + N];
        }
        for (int i = 1; i <= 2 * N; i++)
          arr[i] = arr_2[i];
      } else {
        for (int i = 1 + oper; i <= 2 * N; i++)
          arr_2[i - oper] = arr[i];
        for (int i = 1; i <= oper; i++)
          arr_2[2 * N - oper + i] = arr[i];
        for (int i = 1; i <= 2 * N; i++)
          arr[i] = arr_2[i];
      }
    }
    for (int i = 1; i <= 2 * N; i++)
      cout << arr[i] << endl;
  }
  // while(1);
  return 0;
}
Problem p00436 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  vector<int> card, tmp;

  scanf("%d%d", &n, &m);
  n *= 2;
  card.resize(n);
  tmp.resize(n);

  for (int i = 0; i < n; ++i)
    card[i] = 1 + i;

  for (int i = 0; i < m; ++i) {

    int k;

    scanf("%d", &k);

    if (k == 0) {

      for (int i = 0; i < n / 2; ++i) {
        tmp[i * 2] = card[i];
        tmp[i * 2 + 1] = card[i + n / 2];
      }
    } else {
      for (int i = 0; i < n - k; ++i)
        tmp[i] = card[i + k];
      for (int i = 0; i < k; ++i)
        tmp[n - k + i] = card[i];
    }
    card = tmp;
  }
  for (int i = 0; i < n; ++i)
    printf("%d\\n", card[i]);
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  vector<int> card, tmp;

  scanf("%d%d", &n, &m);
  n *= 2;
  card.resize(n);
  tmp.resize(n);

  for (int i = 0; i < n; ++n)
    card[i] = 1 + i / 2;

  for (int i = 0; i < m; ++i) {

    int k;

    scanf("%d", &k);

    if (k == 0) {

      for (int i = 0; i < n / 2; ++i) {
        tmp[i * 2] = card[i];
        tmp[i * 2 + 1] = card[i + n / 2];
      }
    } else {
      for (int i = 0; i < n - k; ++i)
        tmp[i] = card[i + k];
      for (int i = 0; i < k; ++i)
        tmp[n - k + i] = card[i];
    }
    card = tmp;
  }
  return 0;
}
Problem p00436 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;
int main(void) {
  int card[2][202] = {{0}};

  int n;
  scanf("%d", &n);
  for (int i = 0; i < 2 * n; i++) {
    card[0][i] = i + 1;
  }

  int idx = 0;
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int k;
    scanf("%d", &k);
    if (k == 0) {
      for (int j = 0; j < 2 * n; j++) {
        if (j < n)
          card[1 - idx][2 * j] = card[idx][j];
        else
          card[1 - idx][2 * (j - n) + 1] = card[idx][j];
      }
    } else {
      for (int j = 0; j < 2 * n; j++) {
        if (j < k)
          card[1 - idx][2 * n - k + j] = card[idx][j];
        else
          card[1 - idx][j - k] = card[idx][j];
      }
    }
    idx = 1 - idx;
  }
  for (int i = 0; i < 2 * n; i++) {
    printf("%d\\n", card[idx][i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
using namespace std;

int card[3][300] = {{0}};

void r(int idx, int n);
void s(int idx, int n, int k);

int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n * 2; i++) {
    card[0][i] = i + 1;
  }

  int m;
  scanf("%d", &m);
  int idx = 0;
  for (int i = 0; i < m; i++) {
    int k;
    scanf("%d", &k);
    if (k == 0) {
      r(idx, n);
    } else {
      s(idx, n, k);
    }
    idx = 1 - idx;
  }
  for (int i = 0; i < 2 * n; i++) {
    printf("%d\\n", card[idx][i]);
  }
  return 0;
}

void r(int idx, int n) {
  for (int i = 0; i < 2 * n; i++) {
    if (i < n)
      card[1 - idx][2 * i] = card[idx][i];
    card[1 - idx][2 * (i - n) + 1] = card[idx][i];
  }
  return;
}

void s(int idx, int n, int k) {
  for (int i = 0; i < 2 * n; i++) {
    if (i >= k) {
      card[1 - idx][i - k] = card[idx][i];
    } else if (i < k) {
      card[1 - idx][i + 2 * n - k] = card[idx][i];
    }
  }
  return;
}
Problem p00436 (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)

int n;

void rfl(vector<int> &card) {
  vector<int> nxt;
  for_(i, 0, n) {
    nxt.push_back(card[i]);
    nxt.push_back(card[n + i]);
  }
  card = nxt;
}

void cut(vector<int> &card, int k) {
  vector<int> nxt;
  for_(i, k, 2 * n) nxt.push_back(card[i]);
  for_(i, 0, k) nxt.push_back(card[i]);
  card = nxt;
}

int main() {
  cin >> n;
  vector<int> card(2 * n);
  for_(i, 0, 2 * n) card[i] = i + 1;
  int m;
  cin >> m;
  for_(i, 0, m) {
    int k;
    cin >> k;
    if (k)
      cut(card, k);
    else
      rfl(card);
  }
  for_(i, 0, 2 * n) cout << card[i] << endl;
  return 0;
}

Error: WA

Fixed submission:

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

#define for_(i, a, b) for (int i = a; i < b; ++i)

int n;

void rfl(vector<int> &card) {
  vector<int> nxt;
  for_(i, 0, n) {
    nxt.push_back(card[2 * i]);
    nxt.push_back(card[2 * i + 1]);
  }
  card = nxt;
}

void cut(vector<int> &card, int k) {
  vector<int> nxt;
  for_(i, k, n) nxt.push_back(card[i]);
  for_(i, 0, k) nxt.push_back(card[i]);
  card = nxt;
}

int main() {
  cin >> n;
  vector<int> card(n);
  for_(i, 0, 2 * n) card[i] = i + 1;
  int m;
  cin >> m;
  for_(i, 0, m) {
    int k;
    cin >> k;
    if (k == 0)
      rfl(card);
    else
      cut(card, k);
  }
  for_(i, 0, n) cout << card[i] << endl;
  return 0;
}
Problem p00436 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int card, place[201], m, change, ba[201], ko;
  cin >> card;
  for (int i = 1; i <= 2 * card; i++) {
    place[i] = i;
    // cout<<place[i]<<endl;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> change;
    if (change == 0) {
      ko = 1;
      for (int j = 1; j <= 2 * card; j++) {
        if (j % 2 == 1) {
          ba[j] = place[ko];
        } else {
          ba[j] = place[ko + card];
          ko++;
        }
      }
      for (int j = 1; j <= 2 * card; j++)
        place[j] = ba[j];
    }

    else {
      ko = 1;
      for (int j = 1; j <= 2 * card; j++) {
        if (2 * card - j >= change) {
          ba[j] = place[change + j];
          //    cout<<"1"<<endl;
        } else {
          ba[j] = place[ko];
          //      cout<<"2"<<endl;
          ko++;
        }
      }
      for (int j = 1; j <= card * 2; j++)
        place[j] = ba[j];
    }
  }
  for (int i = 1; i <= 2 * card; i++)
    cout << place[i] << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int card, place[201], m, change, ba[101], co, ca[101], ko;
  cin >> card;
  for (int i = 1; i <= 2 * card; i++) {
    place[i] = i;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> change;
    if (change == 0) {
      co = 0;
      ko = 0;
      for (int j = 1; j <= 2 * card; j++) {
        if (j <= card) {
          ba[co] = place[j];
          co++;
        } else {
          ca[ko] = place[j];
          ko++;
        }
        //  cout<<ba[co]<<" "<<ca[co]<<endl;
      }
      co = 0;
      for (int j = 1; j <= 2 * card; j++) {
        if (j % 2 == 1)
          place[j] = ba[co];
        else {
          place[j] = ca[co];
          co++;
        }
      }
    } else {
      co = 0;
      ko = 0;
      for (int j = 1; j <= 2 * card; j++) {
        if (j <= change) {
          ba[co] = place[j];
          co++;
        } else {
          ca[ko] = place[j];
          ko++;
        }
      }
      co = 0;
      ko = 0;
      for (int j = 1; j <= 2 * card; j++) {
        if (j <= 2 * card - change) {
          place[j] = ca[co];
          co++;
        } else {
          place[j] = ba[ko];
          ko++;
        }
      }
    }
  }
  for (int i = 1; i <= 2 * card; i++)
    cout << place[i] << endl;
}
Problem p00436 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int cards[201];
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 2 * n; i++)
    cards[i] = i + 1;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (!k) {
      // a == 0 --- refleshuffle
      int a[101];
      int b[101];
      for (int i = 0; i < n; i++) {
        a[i] = cards[i];
        b[i] = cards[i + n];
      }
      for (int i = 0; i < n; i++) {
        cards[2 * i] = a[i];
        cards[2 * i + 1] = b[i];
      }
    } else {
      // cut
      int a[201], b[201];
      for (int i = 0; i < k; i++)
        a[i] = cards[i];
      for (int i = 0; i < 2 * n - k; i++)
        b[i] = cards[i + k];
      for (int i = 0; i < 2 * n - k; i++)
        cards[i] = b[i];
      for (int i = 0; i < k; i++)
        cards[i + (2 * n - k)] = a[i];
    }
  }
  for (int i = 0; i < 2 * n; i++) {
    cout << cards[i] << endl;
  }
  char c;
  cin >> c;
  return 0;
}

Error: TLE

Fixed submission:

// #0513
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m;
  vector<int> l;
  vector<int> _l;
  for (int i = 0; i < 2 * n; i++) {
    l.push_back(i + 1);
  }
  for (int i = 0; i < m; i++) {
    cin >> k;
    for (int i = 0; i < 2 * n; i++) {
      _l.push_back(l[i]);
    }
    if (k == 0) {
      // refleshuffle
      for (int i = 0; i < n; i++) {
        l.insert(l.begin() + (2 * i), _l[i]);
        l.insert(l.begin() + (2 * i + 1), _l[n + i]);
      }
    } else {
      // cut
      for (int i = 0; i < 2 * n - k; i++) {
        l.insert(l.begin() + i, _l[i + k]);
      }
      for (int i = 0; i < k; i++) {
        l.insert(l.begin() + 2 * n - i + k, _l[i]);
      }
    }
    _l.clear();
  }
  for (int i = 0; i < 2 * n; i++) {
    cout << l[i] << endl;
  }
}