# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
466243 | CyberCow | Xor Sort (eJOI20_xorsort) | C++17 | 158 ms | 12432 KiB |
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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
using namespace std;
using ll = long long;
vector <int> v;
vector <pair<int, int>> ans;
void bubbleSort()
{
int i, j;
bool swapped;
for (i = 0; i < v.size() - 1; i++)
{
swapped = false;
for (j = 0; j < v.size() - i - 1; j++)
{
if (v[j] > v[j + 1])
{
swap(v[j], v[j + 1]);
swapped = true;
ans.push_back({j, j + 1});
ans.push_back({j + 1, j});
ans.push_back({j, j + 1});
}
}
if (swapped == false)
break;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int x, n, i, j, s;
cin >> n >> s;
for ( i = 0; i < n; i++)
{
cin >> x;
v.push_back(x);
}
bubbleSort();
cout << ans.size() << endl;
for ( i = 0; i < ans.size(); i++)
{
cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |