Problem: 2049C - MEX Cycle
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <algorithm>

#include <string>

#include <cstring>

#include <cmath>

#include <iomanip>

#include <queue>

#include <vector>

#include <stack>

#include <functional>

#include <array>

#include <set>

#include <map>

#include <unordered_map>

#include <unordered_set>



using namespace std;



#define ll long long

#define mod 998244353

const int N = 1e6 + 5;

ll oo = 0x3f3f3f3f3f3f3f3f;

int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};

int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};

char ch[] = {'R', 'L', 'U', 'D'};



int main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  cout.tie(nullptr);



  if (fopen("input.txt", "r"))

  {

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

  }



  int t = 1;

  cin >> t;



  while (t--)

  {

    int n, m, k;

    cin >> n >> m >> k;

    vector<int> v(n + 1);

    v[k] = 1e9;

    if (m == 1)

      v[n] = 1;

    else

      v[m - 1] = 1;

    if (m == n)

      v[1] = 1;

    else

      v[m + 1] = 1;



    for (int i = 1; i <= n; i++)

    {

      if (i == m)

        continue;

      if (i == k)

      {

        int j = 0;

        vector<int> a;

        if (i == 1)

        {

          a.push_back(v[n]);

        }

        else

          a.push_back(v[i - 1]);



        if (i == n)

          a.push_back(v[1]);



        else

          a.push_back(v[i + 1]);

        if ((i + 1) % n != m % n && (i - 1 != m || (i == 1 && m != n)))

          a.push_back(v[m]);

        sort(a.begin(), a.end());

        for (auto it : a)

        {

          if (it == j)

            j++;

        }

        v[i] = j;

      }

      else

      {

        int j = 0;

        vector<int> a;

        if (i == 1)

        {

          a.push_back(v[n]);

        }

        else

          a.push_back(v[i - 1]);



        if (i == n)

          a.push_back(v[1]);

        else

          a.push_back(v[i + 1]);

        sort(a.begin(), a.end());

        for (auto it : a)

        {

          if (it == j)

            j++;

        }

        v[i] = j;

      }

    }

    for (int i = 1; i <= n; i++)

      cout << v[i] << " ";

    cout << '\n';

  }

  return 0;

}

Submission (verdict: Accepted):
#include <iostream>

#include <algorithm>

#include <string>

#include <cstring>

#include <cmath>

#include <iomanip>

#include <queue>

#include <vector>

#include <stack>

#include <functional>

#include <array>

#include <set>

#include <map>

#include <unordered_map>

#include <unordered_set>



using namespace std;



#define ll long long

#define mod 998244353

const int N = 1e6 + 5;

ll oo = 0x3f3f3f3f3f3f3f3f;

int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};

int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};

char ch[] = {'R', 'L', 'U', 'D'};



int main()

{

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  cout.tie(nullptr);



  if (fopen("input.txt", "r"))

  {

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

  }



  int t = 1;

  cin >> t;



  while (t--)

  {

    int n, m, k;

    cin >> n >> m >> k;

    vector<int> v(n + 1);

    v[k] = 1e9;

    if (m == 1)

      v[n] = 1;

    else

      v[m - 1] = 1;

    if (m == n)

      v[1] = 1;

    else

      v[m + 1] = 1;

    int q = 10;

    while (q--)

    {

      for (int i = 1; i <= n; i++)

      {

        if (i == m)

          continue;

        if (i == k)

        {

          int j = 0;

          vector<int> a;

          if (i == 1)

          {

            a.push_back(v[n]);

          }

          else

            a.push_back(v[i - 1]);



          if (i == n)

            a.push_back(v[1]);



          else

            a.push_back(v[i + 1]);

          if ((i + 1) % n != m % n && (i - 1 != m || (i == 1 && m != n)))

            a.push_back(v[m]);

          sort(a.begin(), a.end());

          for (auto it : a)

          {

            if (it == j)

              j++;

          }

          v[i] = j;

        }

        else

        {

          int j = 0;

          vector<int> a;

          if (i == 1)

          {

            a.push_back(v[n]);

          }

          else

            a.push_back(v[i - 1]);



          if (i == n)

            a.push_back(v[1]);

          else

            a.push_back(v[i + 1]);

          sort(a.begin(), a.end());

          for (auto it : a)

          {

            if (it == j)

              j++;

          }

          v[i] = j;

        }

      }

    }

    for (int i = 1; i <= n; i++)

      cout << v[i] << " ";

    cout << '\n';

  }

  return 0;

}