Submission #405700

#TimeUsernameProblemLanguageResultExecution timeMemory
405700radaiosm7Xor Sort (eJOI20_xorsort)C++98
100 / 100
12 ms1092 KiB
#include <bits/stdc++.h> using namespace std; int n, cc, s, i, k, curr, j, mx; vector<pair<int, int> > ans; int a[1005], b[1005]; bool hasBit; 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, i); ++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; } } else { for (i=19; i >= 0; --i) { hasBit = false; for (j=1; j <= n; ++j) { if ((a[j]>>i)&1) { hasBit = true; } } if (hasBit) { for (j=2; j <= n; ++j) { if (!((a[j]>>i)&1)) { oper(j, j-1); } } for (j=1; j < n; ++j) { if ((a[j]>>i)&1) { oper(j, j+1); } } --n; } } } 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 (stderr)

xorsort.cpp: In function 'int main()':
xorsort.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d%d", &n, &s);
      |   ~~~~~^~~~~~~~~~~~~~~~
xorsort.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...