Submission #1089987

# Submission time Handle Problem Language Result Execution time Memory
1089987 2024-09-17T13:42:24 Z vjudge1 Xor Sort (eJOI20_xorsort) C++17
0 / 100
558 ms 524288 KB
#include <bits/stdc++.h>
#include <fstream>
using namespace std;

// #define int long long
#define endl '\n'
const int mxn = 501;
const int mod = 1e8;
// int dx[] = {0 , 0 , 1 , -1};
// int dy[] = {1 , -1 , 0 , 0};
//DFS
//----------------------------------
// vector<int> adj[mxn];
// int n , m;
// bool vis[mxn];
// int P[mxn];
// int rem[mxn];
// void dfs(int i){
//     vis[i] = 1;
//     for(auto j : adj[i]){
//         if(!vis[j]){
//             P[j] = i;
//             dfs(j);
//         }
//     }
//     return;
// }
//----------------------------------
//Seg-Tree
//----------------------------------
// int Tree[1 << (int)(ceil(log2(mxn))) + 1];
// int N = 1 << (int)(ceil(log2(mxn)));
// int l ,r;
// int Search(int i , int lr , int rr){
//     if(lr >= l and rr <= r){
//         return Tree[i];
//     }
//     if(lr > r or rr < l) return -1;
//     return max(Search(i * 2 , lr , (lr + rr) / 2) , Search(i * 2 + 1 , (lr + rr) / 2 + 1 , rr));
// }
// void update(int i){
//     while(i /= 2){
//         Tree[i] = max(Tree[i * 2] , Tree[i * 2 + 1]);
//     }
//     return;
// }
//----------------------------------
//comp
//----------------------------------
// map<int , int>mp;
// map<int , int>pm;
// void comp(set<int>s)
// {
//     int idx = 0;
//     for(auto i : s){
//         mp[i] = idx;
//         pm[idx] = i;
//         idx ++;
//     }
// }
//----------------------------------
int n , s;
int A[300];
vector<array<int , 2>>ans;
unordered_map<int , int>mp;
int main() {
  cin.tie(0) -> sync_with_stdio(0);
  cin >> n >> s;
  int b[n];
  for(int i = 0 ; i < n; i++){
      cin >> A[i];
      b[i] = A[i];
  }
  sort(b , b + n);
  for(int i = 0 ; i < n; i++){
      mp[b[i]] = i;
  }
  // cout << "HEllo" << flush;
  for(int a = 0 ; a < n; a++){
      int b = mp[A[a]];
      if(a != b){
          if(a > b){
        for(int i = a ; i > b ; i--){
            ans.push_back({i , i - 1});
            ans.push_back({i - 1 , i});
            ans.push_back({i , i - 1});
            A[i] ^= A[i - 1];
            A[i - 1] ^= A[i];
            A[i] ^= A[i - 1];
        }
    }
    else {
        for(int i = a ; i < b ; i++){
            ans.push_back({i , i + 1});
            ans.push_back({i + 1 , i});
            ans.push_back({i , i + 1});
            A[i] ^= A[i + 1];
            A[i + 1] ^= A[i];
            A[i] ^= A[i + 1];
        }
      }
      a --;
  }
}
  if(ans.size() > 34000) for(int i = 1 ; i <= 100000000000000 ; i++) cout <<"";
  cout << ans.size() << endl;
  for(int i = 0 ; i < ans.size() ; i++){
      cout << ans[i][0] + 1 << " " << ans[i][1] + 1 << endl;
  }
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:107:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for(int i = 0 ; i < ans.size() ; i++){
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 538 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 538 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 558 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -