Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <bits/extc++.h>
- #include <tr2/dynamic_bitset>
- #define int int64_t
- using namespace std;
- using namespace __gnu_pbds;
- using namespace __gnu_cxx;
- typedef std::tr2::dynamic_bitset<> bitvector;
- template<typename T>
- using or_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
- template<typename T>
- using or_multiset = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;
- int g_sort(vector<int> &a){
- int cnt = 0;
- while(true){
- pair<int, int> fnd = {-1, -1};
- for(int i = 0; i < a.size() - 1; i++)
- for(int j = i + 1; j < a.size(); j++)
- if(a[i] > a[j] && (fnd.second == -1 || a[i] - a[j] > a[fnd.first] - a[fnd.second]))
- fnd.first = i, fnd.second = j;
- if(fnd.first == fnd.second)
- break;
- swap(a[fnd.first], a[fnd.second]);
- cnt++;
- }
- return cnt;
- }
- void solve(){
- vector<int> a = {12,7,18,2,9,11,4,5,19,8,0,15,13,1,10,3,14,6,17,16};
- cout << g_sort(a);
- }
- int32_t main() {
- int test_case = 1;
- //cin >> test_case;
- while(test_case--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment