Submission #442158

#TimeUsernameProblemLanguageResultExecution timeMemory
442158elazarkorenXor Sort (eJOI20_xorsort)C++17
25 / 100
169 ms12440 KiB
#include <iostream> #include <vector> #include <algorithm> #define x first #define y second using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vii; vi a; vii ans; void Xor(int i, int j) { a[i] ^= a[j]; ans.push_back({i, j}); } void Swap(int i, int j) { Xor(j, i); Xor(i, j); Xor(j, i); // ans.push_back({j, i}); // ans.push_back({i, j}); // ans.push_back({j, i}); // swap(a[i], a[j]); } int main() { int n, s; cin >> n >> s; a.resize(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; while (true) { bool is_new = false; for (int i = 1; i < n; i++) { if (a[i] > a[i + 1]) { Swap(i, i + 1); is_new = true; } } if (!is_new) break; } cout << ans.size() << '\n'; for (int i = 0; i < ans.size(); i++) { cout << ans[i].x << ' ' << ans[i].y << '\n'; } }

Compilation message (stderr)

xorsort.cpp: In function 'int main()':
xorsort.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...