Submission #775079

# Submission time Handle Problem Language Result Execution time Memory
775079 2023-07-06T07:27:13 Z Polar_Bear_2007 Xor Sort (eJOI20_xorsort) C++17
0 / 100
1 ms 212 KB
// #pragma GCC optimize("Ofast,unroll-loops")

#ifdef MINHDEPTRAI
 
#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/bits/stdc++.h"
#include <chrono>
#define __gcd(a, b) gcd(a, b)
using namespace std ::chrono;
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define foru(i, a, b) for (int i = a; i <= b; ++i)
#define ford(i, a, b) for (int i = a; i >= b; --i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp(a, b) make_pair(a, b)
// #define int long long
typedef pair<int, int>  pii;
typedef pair<pair<int, int>, int> piii;
#define endl '\n'
const string name_minh = "9";
#define int long long
const int maxN = 2e5 + 5;
const int mod = 1;

const int inf = 1e9;
int n, arr[maxN], k;
map<int, int> counting;
void solve(){
    cin >> n >> k;
    foru(i, 1, n){
        cin >> arr[i];
        counting[arr[i]]++;
    }
    vector<pair<int, int>> ans;
    map<int, int>:: iterator it;
    foru(i, 1, n){
        foru(j, 1, n - i){
            if(arr[j] > arr[j + 1]){
                it = counting.find(arr[j] ^ arr[j + 1]);

                if((arr[j] ^ arr[j + 1]) < arr[j + 1] && it == counting.end()){
                    ans.push_back(mp(j, j + 1));
                    arr[j] = arr[j] ^ arr[j + 1];
                }
                else{
                    swap(arr[j], arr[j + 1]);
                    ans.push_back(mp(j + 1, j));
                    ans.push_back(mp(j, j + 1));
                    ans.push_back(mp(j + 1, j));
                }
            }

        }
    }
 
    cout << ans.size() << endl;
    for(pair<int, int> x: ans){
        cout << x.first << " " << x.second << endl;
    }
    
}
signed main(){
    IOS
    // #ifdef MINHDEPTRAI 
    // ifstream cin(name_minh + ".in");
    // ofstream cout(name_minh + ".out");
    // #endif
    solve();
   
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 1 ms 212 KB Not sorted
3 Halted 0 ms 0 KB -