Submission #443135

#TimeUsernameProblemLanguageResultExecution timeMemory
443135AdamGSXor Sort (eJOI20_xorsort)C++14
65 / 100
12 ms1356 KiB
#include<bits/stdc++.h> using namespace std; #define rep(a, b) for(int a = 0; a < (b); ++a) #define pb push_back #define st first #define nd second const int LIM=1e3+7; int T[LIM], n; vector<pair<int,int>>ans; void solve2() { for(int i=19; i>=0; --i) { if(!n) break; bool bylo=false; rep(j, n-1) { if(T[j]&(1<<i)) { bylo=true; if(!(T[j+1]&(1<<i))) { ans.pb({j+1, j}); T[j+1]^=T[j]; } ans.pb({j, j+1}); T[j]^=T[j+1]; } } if(bylo) --n; } } void solve1() { rep(i, n) for(int j=n-1; j>i; --j) { if(T[j-1]>T[j]) { ans.pb({j, j-1}); ans.pb({j-1, j}); ans.pb({j, j-1}); swap(T[j], T[j-1]); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int typ; cin >> n >> typ; rep(i, n) cin >> T[i]; if(typ==2) solve2(); else solve1(); cout << ans.size() << '\n'; for(auto i : ans) cout << i.st+1 << " " << i.nd+1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...