Submission #775325

#TimeUsernameProblemLanguageResultExecution timeMemory
775325Antonn_114Xor Sort (eJOI20_xorsort)C++14
60 / 100
7 ms984 KiB
#include <bits/stdc++.h> using namespace std; // Write down the limits of the problem here int main() { // Try to avoid cin, cout :) int tc = 1; // scanf("%d", &tc); while(tc--) { /// Your solution here int n, s; scanf("%d%d", &n, &s); vector<int> a(n); vector<pair<int, int>> actions; for (auto&i : a) scanf("%d", &i); if (s == 1){ vector<int> c = a; map<int, int> bbb; for (int i = 0; i < n; i++){ bbb[a[i]] = i; } for (int i = 0; i < n - 1; i++){ actions.push_back({i, i + 1}); c[i] ^= c[i + 1]; } int lol = 0; for (auto it = bbb.rbegin(); it != bbb.rend(); it++){ for (int j = it->second; j < n - 1 - lol; j++){ actions.push_back({j + 1, j}); c[j + 1] ^= c[j]; bbb[a[j + 1]]--; a[j] = a[j + 1]; } for (int j = max(it->second - 1, 0); j < n - lol - 1; j++){ actions.push_back({j, j + 1}); c[j] ^= c[j + 1]; } lol++; } printf("%d\n", int(actions.size())); for (auto &i : actions){ printf("%d %d\n", i.first + 1, i.second + 1); } } else if (s == 2){ bool beau = false; for (int i = 19; i >= 0; i--){ vector<int> ids; for (int j = 0; j < n; j++){ if ((a[j] >> i) & 1){ ids.push_back(j); } } if (!ids.empty()){ if (!beau){ for (auto &j : ids){ int ptr = j; while(ptr > 0){ actions.push_back({ptr - 1, ptr}); ptr--; } } int ptr = *ids.rbegin(); while(ptr < n - 1){ actions.push_back({ptr + 1, ptr}); ptr++; } for (int j = 0; j < n - 1; j++){ actions.push_back({j, j + 1}); } beau = true; }else{ for (auto &j : ids){ int ptr = j; while(ptr > 0){ actions.push_back({ptr - 1, ptr}); ptr--; } } int ptr = *ids.rbegin(); while(ptr < n - 2){ actions.push_back({ptr + 1, ptr}); ptr++; } } } } printf("%d\n", int(actions.size())); for (auto& i : actions){ printf("%d %d\n", i.first + 1 ,i.second + 1); } } } return 0; } /* * Ermm don't underestimate Div2A, pls... * * IMPORTANT:: If there isn't a clear-cut approach for your program, DO NOT CODE YET! * * Analyze the time complexity and space complexity even if it *seems* efficient * * Write down some notes for more complicated problems * * Also, please, CP isn't supposed to be complicated * **/

Compilation message (stderr)

xorsort.cpp: In function 'int main()':
xorsort.cpp:13:14: 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:17:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         for (auto&i : a) scanf("%d", &i);
      |                          ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...