Submission #1025346

#TimeUsernameProblemLanguageResultExecution timeMemory
1025346tolbiXor Sort (eJOI20_xorsort)C++17
40 / 100
42 ms1492 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); int n,s;cin>>n>>s; vector<int> arr(n); for (int i = 0; i < n; ++i) { cin>>arr[i]; } vector<int> barr = arr; vector<pair<int,int>> ansarr; for (int bit = 22; bit >= 0; bit--){ for (int i = 0; i+1 < n; i++){ if (arr[i]&(1LL<<bit)){ if (arr[i+1]&(1LL<<bit)){ ansarr.push_back({i+1,i+2}); arr[i]^=arr[i+1]; } else { ansarr.push_back({i+2,i+1}); ansarr.push_back({i+1,i+2}); arr[i+1]^=arr[i]; arr[i]^=arr[i+1]; } } } if ((n>=1) && (arr[n-1]&(1LL<<bit))){ n--; } } cout<<ansarr.size()<<endl; for (int i = 0; i < ansarr.size(); ++i) { cout<<ansarr[i].first<<" "<<ansarr[i].second<<endl; } }

Compilation message (stderr)

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