Submission #720140

# Submission time Handle Problem Language Result Execution time Memory
720140 2023-04-07T13:41:18 Z fuad27 Xor Sort (eJOI20_xorsort) C++17
65 / 100
73 ms 1160 KB
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
void sw(int i, int j) {
	v.push_back({j, i});
	v.push_back({i, j});
	v.push_back({j, i});
}
int main () {
  int n, s;
  cin >> n >> s;
  int a[n];
  for(int i = 0;i<n;i++)cin >> a[i];
  if(s==2) {
    vector<pair<int,int>> op;
    for(int i = 19;i>=0;i--) {
      for(int j = 1;j<n;j++) {
        if((a[j]&(1<<i))==0 and (a[j-1]&(1<<i))!=0) {
          a[j]^=a[j-1];
          op.push_back({j,j-1});
        }
        if((a[j-1]&(1<<i))!=0) {
          if((a[j-1]^a[j])<a[j-1]) {
            a[j-1]^=a[j];
            op.push_back({j-1,j});
          }
        }
      }
    }
    cout << op.size() << "\n";
    for(auto i:op) {
      cout << i.first+1 << " " << i.second+1 << "\n";
    }
  }
  else {
    for(int i = 1;i<=n;i++) {
      bool check = false;
      for(int j = 0;j<n-i;j++) {
        if(a[j] > a[j+1]) {
          sw(j+1, j+2);
          swap(a[j], a[j+1]);
          check = true;
        }
      }
      if(!check)break;
    }
    cout<<v.size()<<endl;
    for(auto [i, j]:v) {
      cout<<i<<' '<<j<<endl;
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 23 ms 636 KB Output is correct
5 Correct 30 ms 600 KB Output is correct
6 Correct 21 ms 596 KB Output is correct
7 Correct 22 ms 684 KB Output is correct
8 Correct 23 ms 640 KB Output is correct
9 Correct 23 ms 608 KB Output is correct
10 Correct 25 ms 608 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 42 ms 860 KB Output is correct
13 Correct 48 ms 964 KB Output is correct
14 Correct 44 ms 848 KB Output is correct
15 Correct 45 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 23 ms 636 KB Output is correct
5 Correct 30 ms 600 KB Output is correct
6 Correct 21 ms 596 KB Output is correct
7 Correct 22 ms 684 KB Output is correct
8 Correct 23 ms 640 KB Output is correct
9 Correct 23 ms 608 KB Output is correct
10 Correct 25 ms 608 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 42 ms 860 KB Output is correct
13 Correct 48 ms 964 KB Output is correct
14 Correct 44 ms 848 KB Output is correct
15 Correct 45 ms 900 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 24 ms 664 KB Output is correct
18 Correct 44 ms 804 KB Output is correct
19 Correct 39 ms 848 KB Output is correct
20 Correct 39 ms 840 KB Output is correct
21 Correct 49 ms 836 KB Output is correct
22 Correct 42 ms 980 KB Output is correct
23 Correct 41 ms 860 KB Output is correct
24 Correct 39 ms 916 KB Output is correct
25 Correct 37 ms 848 KB Output is correct
26 Incorrect 73 ms 1160 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 6 ms 848 KB Output is correct
6 Correct 5 ms 848 KB Output is correct
7 Correct 6 ms 848 KB Output is correct
8 Correct 6 ms 900 KB Output is correct
9 Correct 6 ms 848 KB Output is correct
10 Correct 6 ms 848 KB Output is correct
11 Correct 5 ms 848 KB Output is correct
12 Correct 7 ms 848 KB Output is correct
13 Correct 6 ms 848 KB Output is correct
14 Correct 7 ms 844 KB Output is correct
15 Correct 7 ms 972 KB Output is correct