Submission #529245

# Submission time Handle Problem Language Result Execution time Memory
529245 2022-02-22T14:22:54 Z Itamar Xor Sort (eJOI20_xorsort) C++14
0 / 100
2 ms 472 KB
#include <map>
using namespace std;
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <iostream>

int main()
{
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[i] = x;
    }
    vector<pair<int, int>> ans;
    int k = 0;
    int t = 1;
    while (t < 1e6) {
        t *= 2;
    }
    t = t / 2;
    while(t > 0){
        for (int j = 0; j < a.size() - 1; j++) {
            if (a[j] >= t) {
                if (a[j + 1] >= t) {
                    a[j] = a[j] ^ a[j + 1];
                    k++;
                    ans.push_back({ j, j + 1 });
                }
                else {
                    a[j+1] = a[j] ^ a[j + 1];
                    k++;
                    ans.push_back({ j+1, j});
                    a[j] = a[j] ^ a[j + 1];
                    k++;
                    ans.push_back({ j, j + 1 });
                }
            }
        }
        if (a[a.size() - 1] >= t) {
            a.pop_back();
        }
        t = t/2;
    }
    cout << k << "\n";
    for (int i = 0; i < k; i++) {
        cout << ans[i].first+1 << ' ' << ans[i].second+1 << "\n";
    }
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for (int j = 0; j < a.size() - 1; j++) {
      |                         ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 472 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -