Submission #631703

# Submission time Handle Problem Language Result Execution time Memory
631703 2022-08-18T13:50:41 Z CyberCow Xor Sort (eJOI20_xorsort) C++17
0 / 100
1 ms 212 KB
#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])
            {
                swapped = true;
                if (v[j] < (v[j] ^ v[j + 1]))
                {
                    ans.push_back({ j + 1, j });
                    v[j + 1] ^= v[j];
                }
                else if((v[j] ^ v[j + 1]) < v[j + 1])
                {
                    ans.push_back({ j, j + 1 });
                    v[j] ^= v[j + 1];
                }
                else if(v[j + 1] < (v[j] ^ v[j + 1]))
                {
                    ans.push_back({ j + 1, j });
                    v[j + 1] ^= v[j];
                    ans.push_back({ j, j + 1 });
                    v[j] ^= v[j + 1];
                }
                else
                {
                    ans.push_back({ j, j + 1 });
                    v[j] ^= v[j + 1];
                    ans.push_back({ j + 1, j });
                    v[j + 1] ^= v[j];
                }
            }
        }
        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';
    }
   /* for ( i = 0; i < n; i++)
    {
        cout << v[i] << ' ';
    }*/
    return 0;
}

Compilation message

xorsort.cpp: In function 'void bubbleSort()':
xorsort.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (i = 0; i < v.size() - 1; i++)
      |                 ~~^~~~~~~~~~~~~~
xorsort.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (j = 0; j < v.size() - i - 1; j++)
      |                     ~~^~~~~~~~~~~~~~~~~~
xorsort.cpp: In function 'int main()':
xorsort.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
xorsort.cpp:64:18: warning: unused variable 'j' [-Wunused-variable]
   64 |     int x, n, i, j, s;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Not sorted
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Not sorted
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Not sorted
2 Halted 0 ms 0 KB -