Submission #405527

# Submission time Handle Problem Language Result Execution time Memory
405527 2021-05-16T14:02:19 Z radaiosm7 Xor Sort (eJOI20_xorsort) C++
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
int n, s, i, k, curr, j, mx;
vector<pair<int, int> > ans;
int a[1005], b[1005];

void oper(int x, int y) {
  a[x] ^= a[y];
  ans.push_back(make_pair(x,y));
}

int main() {
  scanf("%d%d", &n, &s);

  for (i=1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }

  if (s == 1) {
    for (i=n; i >= 1; --i) {
      for (j=1; j <= min(n-1, k); ++j) {
        oper(j, j+1);
      }

      curr = 1;
      for (j=2; j <= i; ++j) {
        if (b[j]>b[curr]) {
          curr = j;
        }
      }

      for (j=curr-2; j >= 1; --j) {
        oper(j, j+1);
      }

      for (j=curr+1; j <= i; ++j) {
        oper(j, j-1);
      }

      mx = b[curr];
      for (j=curr; j < i; ++j) {
        b[j] = b[j+1];
      }
      b[i]=mx;
    }
  }

  printf("%d\n", (int)ans.size());
  for (i=0; i < (int)ans.size(); ++i) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d%d", &n, &s);
      |   ~~~~~^~~~~~~~~~~~~~~~
xorsort.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Not sorted
2 Halted 0 ms 0 KB -