Submission #415513

#TimeUsernameProblemLanguageResultExecution timeMemory
415513xyzArranging Shoes (IOI19_shoes)C++17
50 / 100
1057 ms3108 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; typedef long long ll; ll count_swaps(vector<int> s) { set<pair<int, int>> L, R; int n = s.size(); // for(int i = 0; i < n; i ++){ // if(s[i] < 0) // L.insert({-s[i], i}); // else // R.insert({s[i], i}); // } ll result = 0; for(int i = 0; i < n; i += 2){ int j = i + 1; while(s[j] != -s[i]) ++ j; while(j - 1 > i) swap(s[j], s[j - 1]), ++ result, -- j; if(s[i] > 0) swap(s[j], s[i]), ++ result; // cout << result << endl; // if(!L.count({-s[i], i}) && !R.count({s[i], i})) // continue; // if(s[i] < 0){ // L.erase({-s[i], i}); // auto it = R.lower_bound({-s[i], -1}); // assert(it != R.end()); // result += abs(it->second - (i + 1)); // R.erase(it); // }else{ // R.erase({s[i], i}); // auto it = L.lower_bound({s[i], -1}); // assert(it != L.end()); // result += 1 + abs(it->second - i); // L.erase(it); // } } // cout << result << endl; return result; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...