Submission #367470

# Submission time Handle Problem Language Result Execution time Memory
367470 2021-02-17T13:01:33 Z alextodoran Xor Sort (eJOI20_xorsort) C++17
60 / 100
10 ms 1156 KB
/**
 ____ ____ ____ ____ ____
||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 time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 5 ms 772 KB Output is correct
5 Correct 5 ms 752 KB Output is correct
6 Correct 5 ms 756 KB Output is correct
7 Correct 5 ms 752 KB Output is correct
8 Correct 5 ms 772 KB Output is correct
9 Correct 5 ms 752 KB Output is correct
10 Correct 5 ms 900 KB Output is correct
11 Correct 6 ms 752 KB Output is correct
12 Correct 6 ms 752 KB Output is correct
13 Correct 5 ms 752 KB Output is correct
14 Correct 5 ms 752 KB Output is correct
15 Correct 5 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 5 ms 772 KB Output is correct
5 Correct 5 ms 752 KB Output is correct
6 Correct 5 ms 756 KB Output is correct
7 Correct 5 ms 752 KB Output is correct
8 Correct 5 ms 772 KB Output is correct
9 Correct 5 ms 752 KB Output is correct
10 Correct 5 ms 900 KB Output is correct
11 Correct 6 ms 752 KB Output is correct
12 Correct 6 ms 752 KB Output is correct
13 Correct 5 ms 752 KB Output is correct
14 Correct 5 ms 752 KB Output is correct
15 Correct 5 ms 752 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 5 ms 752 KB Output is correct
18 Correct 8 ms 1008 KB Output is correct
19 Correct 8 ms 1008 KB Output is correct
20 Correct 8 ms 1008 KB Output is correct
21 Correct 10 ms 1008 KB Output is correct
22 Correct 8 ms 1008 KB Output is correct
23 Correct 8 ms 1008 KB Output is correct
24 Correct 8 ms 1008 KB Output is correct
25 Correct 8 ms 1008 KB Output is correct
26 Correct 8 ms 1008 KB Output is correct
27 Correct 9 ms 1008 KB Output is correct
28 Correct 8 ms 1156 KB Output is correct
29 Correct 8 ms 1008 KB Output is correct
30 Correct 8 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 8 ms 1008 KB Output is correct
5 Runtime error 1 ms 492 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -