제출 #1135142

#제출 시각아이디문제언어결과실행 시간메모리
1135142RaduMXor Sort (eJOI20_xorsort)C++20
60 / 100
4 ms972 KiB
#include <bits/stdc++.h> using namespace std; int v[1005]; map <int, int> mp; vector < pair <int, int> > sol; int main() { int n,i,c,k; ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> c; if(c == 1){ for(i = 1; i <= n; i++){ cin >> v[i]; mp[v[i]] = 1; } k = 0; for(auto &x : mp) x.second = ++k; for(i = 1; i <= n; i++) v[i] = mp[v[i]]; for(i = 1; i < n; i++) sol.push_back({i, i + 1}); for(i = n; i >= 2; i--){ int p = 0; for(p = 1; p < i; p++){ if(v[p] == i) break; } for(int j = p; j < i; j++){ sol.push_back({j + 1, j}); swap(v[j], v[j + 1]); } for(int j = max(1, p - 1); j < i; j++) sol.push_back({j, j + 1}); } cout << (int)sol.size() << "\n"; for(auto x : sol) cout << x.first << " " << x.second << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...