Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct OneHandSort {
- std::vector <int> sortShelf(std::vector <int> a) {
- int n = a.size();
- a.emplace_back(-1);
- V<int> ans;
- REP(i, n) {
- if (a[i] == i) continue;
- ans.emplace_back(i);
- std::swap(a[i], a[n]);
- int p = 0;
- REP(j, a.size()) {
- if (a[j] == i) {
- p = j;
- break;
- }
- }
- ans.emplace_back(p);
- std::swap(a[i], a[p]);
- ans.emplace_back(n);
- std::swap(a[p], a[n]);
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement