Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
// LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a) + (size))
#define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v, a) (reverse((v), (v) + (a)))
#define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }

int N, M;

// bool check(vector<int> v)
bool check(int *v) {
  int no[1000];
  for (int i = 1; i <= N; i++) {
    no[i] = i;
  }
  bool flg[1000][1000] = {};
  bool ng = false;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      int a = no[v[j * 2]];
      int b = no[v[j * 2 + 1]];
      if (flg[a][b]) {
        ng = true;
      }
      flg[a][b] = true;
      flg[b][a] = true;
    }
    for (int j = 1; j <= N; j++) {
      no[j]--;
      if (no[j] < 1)
        no[j] = N;
    }
  }
  return ng;
}

int arena[1000010];

signed main() {
  cin >> N >> M;

  int first = ceil(M / 2.0);
  for (int i = 0; i < first; i++) {
    int index = i;
    int sub = (first * 2 - 1) - (index * 2);
    arena[i * 2] = i;
    arena[i * 2 + 1] = i + sub;
  }

  int offset = (first * 2);
  int range = (M * 2 - offset);
  for (int i = first; i < M * 2; i++) {
    int index = i - first;
    int sub = range - (index * 2);
    arena[i * 2] = index + offset;
    arena[i * 2 + 1] = index + offset + sub;
  }

  for (int j = 0; j < M; j++) {
    arena[j * 2]++;
    arena[j * 2 + 1]++;
    int a = arena[j * 2];
    int b = arena[j * 2 + 1];
    cout << a << " " << b << endl;
  }

  // cout << (check(arena) ? "ng" : "ok") << endl;
}


Error: WA

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
// LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a) + (size))
#define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v, a) (reverse((v), (v) + (a)))
#define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }

int N, M;

// bool check(vector<int> v)
bool check(int *v) {
  int no[1000];
  for (int i = 1; i <= N; i++) {
    no[i] = i;
  }
  bool flg[1000][1000] = {};
  bool ng = false;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      int a = no[v[j * 2]];
      int b = no[v[j * 2 + 1]];
      if (flg[a][b]) {
        ng = true;
      }
      flg[a][b] = true;
      flg[b][a] = true;
    }
    for (int j = 1; j <= N; j++) {
      no[j]--;
      if (no[j] < 1)
        no[j] = N;
    }
  }
  return ng;
}

int arena[100010];

signed main() {
  cin >> N >> M;

  int first = ceil(M / 2.0);
  for (int i = 0; i < first; i++) {
    int index = i;
    int sub = (first * 2 - 1) - (index * 2);
    arena[i * 2] = i;
    arena[i * 2 + 1] = i + sub;
  }

  int offset = (first * 2);
  int range = (M * 2 - offset);
  for (int i = first; i < M * 2; i++) {
    int index = i - first;
    int sub = range - (index * 2);
    arena[i * 2] = index + offset;
    arena[i * 2 + 1] = index + offset + sub;
  }

  for (int j = 0; j < M; j++) {
    arena[j * 2]++;
    arena[j * 2 + 1]++;
    int a = arena[j * 2];
    int b = arena[j * 2 + 1];
    cout << a << " " << b << endl;
  }

  // cout << (check(arena) ? "ng" : "ok") << endl;

  // vector<int> v;
  // for (int i = 0; i < N; i++)
  //{
  //	v.push_back(i + 1);
  // }

  // do
  //{
  //	bool ng = check(v);
  //	if (!ng)
  //	{
  //		for (int j = 0; j < M; j++)
  //		{
  //			int a = v[j * 2];
  //			int b = v[j * 2 + 1];
  //			cout << a << " - " << b << endl;
  //		}
  //		return 0;
  //	}

  //} while (next_permutation(v.begin(), v.end()));
}