Submission #670505

#TimeUsernameProblemLanguageResultExecution timeMemory
670505birthdaycakeArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms300 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; long long count_swaps(vector<int>s) { long long n = s.size(); long long ans = 0; map<long long,set<long long>>a; for(int i = 0; i < n; i++){ a[s[i]].insert(-i); } for(int i = n - 1; i >= 0; i--){ if(!a[s[i]].count(-i)) continue; a[s[i]].erase(-i); if(s[i] < 0){ auto x = *a[-s[i]].begin(); ans += (i - (-x)); a[-s[i]].erase(x); }else{ auto x = *a[-s[i]].begin(); ans += (i - (-x) - 1); a[-s[i]].erase(x); } } return ans; }
#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...