Submission #1102051

#TimeUsernameProblemLanguageResultExecution timeMemory
1102051SulAXor Sort (eJOI20_xorsort)C++17
65 / 100
7 ms1236 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define bitcount __builtin_popcountll using namespace std; using namespace __gnu_pbds; using namespace chrono; bool has(int x, int bit) { return (x >> bit) & 1; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n,s; cin >> n >> s; int a[n]; for (int i = 0; i < n; cin >> a[i++]); vector<pair<int,int>> oper; auto operate = [&](int i, int j) { a[i] ^= a[j]; oper.emplace_back(i+1, j+1); }; if (s == 1) { for (int iter = 0; iter < n-1; iter++) { for (int i = 0; i < n-1; i++) { if (a[i] > a[i+1]) { operate(i, i+1); operate(i+1, i); operate(i, i+1); } } } } else { for (int b = 20; b >= 0; b--) { for (int i = 0; i < n-1; i++) { if (a[i+1] >= (1 << b+1)) break; if (has(a[i], b) && !has(a[i+1], b)) { operate(i+1, i); } if (has(a[i], b) && has(a[i+1], b)) { operate(i, i+1); } } } } cout << oper.size() << "\n"; for (auto [i, j] : oper) cout << i << " " << j << "\n"; }

Compilation message (stderr)

xorsort.cpp: In function 'int main()':
xorsort.cpp:38:38: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   38 |                 if (a[i+1] >= (1 << b+1)) break;
      |                                     ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...