Submission #201550

#TimeUsernameProblemLanguageResultExecution timeMemory
201550s_avila_gArranging Shoes (IOI19_shoes)C++14
10 / 100
1093 ms2040 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; long long count_swaps(std::vector<int> s) { bool der = false; int ans = 0; int n = s.size(); for(int i = 0 ; i < n; i++){ der = false; //for(auto x : s) cout<<x<<" "; //cout<<endl; //cout<<s[i]<<" +++++++++ "<<i<<endl; if(s[i] > 0) der = true; int pos = INT_MAX; int m = s.size(); for(int j = i+1; j < m; j++){ if(abs(s[i]) == abs(s[j])){ pos = j; s.erase(s.begin() + j); break; } } //cout<<der<<" "<<i<<" "<<pos<<endl; if(pos == INT_MAX) continue; if(der && pos == i+1){ ans += 1; continue; } if(pos == i + 1 && !der){ continue; } if(der) ans += abs(i - pos); else ans += abs(i - pos) - 1; } 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...