Submission #367470

#TimeUsernameProblemLanguageResultExecution timeMemory
367470alextodoranXor Sort (eJOI20_xorsort)C++17
60 / 100
10 ms1156 KiB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 202;

int n;

int S;

int initial[N_MAX];

int v[N_MAX];

vector <pair <int, int>> ans;

void fxor (int a, int b)
{
    v[a] ^= v[b];
    ans.push_back(make_pair(a, b));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> S;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    for(int i = 1; i <= n; i++)
        initial[i] = v[i];
    for(int k = n; k >= 1; k--)
    {
        for(int i = 1; i < n && i <= k; i++)
            fxor(i, i + 1);
        int pos = -1;
        for(int i = 1; i <= k; i++)
            if(pos == -1 || initial[i] > initial[pos])
                pos = i;
        for(int i = pos - 2; i >= 1; i--)
            fxor(i, i + 1);
        for(int i = pos + 1; i <= k; i++)
            fxor(i, i - 1);
        int aux = initial[pos];
        for(int i = pos; i < k; i++)
            initial[i] = initial[i + 1];
        initial[k] = aux;
    }
    cout << ans.size() << "\n";
    for(pair <int, int> &p : ans)
        cout << p.first << " " << p.second << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...