This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, s, a[1000];
vector<pair<int, int> > res;
int main() {
cin>>n>>s;
for(int i = 0; i < n; i++)
cin>>a[i];
for(int i = 0; i < n; i++) {
int m = i;
for(int j = i + 1; j < n; j++)
if(a[m] > a[j])
m = j;
for(int j = m; j > i; j--) {
res.push_back({j, j - 1});
res.push_back({j - 1, j});
if(s == 1) {
res.push_back({j, j - 1});
swap(a[j - 1], a[j]);
} else {
a[j] ^= a[j - 1];
a[j - 1] ^= a[j];
}
}
}
cout<<res.size()<<'\n';
for(auto i : res)
cout<<i.first + 1<<" "<<i.second + 1<<'\n';
//for(int i = 0; i < n; i++)
// cout<<a[i]<<" ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |