Submission #671784

#TimeUsernameProblemLanguageResultExecution timeMemory
671784mseebacherArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; #define MAXI (int)1e5 long long int count_swaps(vector<int> s){ int n = s.size(); vector<int> pos(n,0); vector<set<int>> schuhe(n+1); for(int i = 0;i<n;i++) { if(s[i] > 0){ schuhe[s[i]].insert(i); } } ll val = 0; for(int i = 0;i<n;i++){ if(s[i] < 0){ int index = *schuhe[-s[i]].begin(); if(index == i+1){ schuhe[-s[i]].erase(index); continue; } if(index == i-1){ schuhe[-s[i]].erase(index); val++; continue; } if(i > index){ val = val + abs(index-i)-(pos[i]-pos[index]); for(int j = index+1;j<i;j++) pos[j]++; }else{ val = val + index-i-1-(pos[index]-pos[i]); for(int j = index+1;j<n;j++) pos[j]--; } schuhe[-s[i]].erase(index); } } return val; }
#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...