# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
468850 | 2021-08-29T20:46:23 Z | mychecksedad | Xor Sort (eJOI20_xorsort) | C++17 | 0 ms | 0 KB |
#include<bits/stdc++.h> using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(0); int n, s, arr[1010]; cin >> n >> s; for(int i = 1; i <= n; i++) cin >> arr[i]; vector<pair<int, int>> ans; if(s == 1){ }else{ for(int bit = 20; bit >= 0; bit--){ for(int i = 1; i < n; i++){ if((1<<bit)&arr[i]){ if((1<<bit)&(arr[i + 1])){ ans.pb({i+1, i}); ans.pb({i, i+1}); arr[i + 1] ^= (1<<bit); arr[i] ^= (1<<bit); }else{ ans.pb({i, i+1}); arr[i] ^= (1<<bit); } } } } } cout << ans.size() << '\n'; for(auto k: ans) cout << k.first << ' ' << k.second << '\n'; return 0; }