Submission #971790

#TimeUsernameProblemLanguageResultExecution timeMemory
971790androArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms348 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; long long count_swaps(std::vector<int> s) { int n = s.size(); map<int,int> M, M1; vector<int> a = s; for(int i = 0 ; i < n; i++) { if(a[i] > 0) { M[a[i]] += 1; } else { M1[a[i]] += 1; } } int ok = 0; for(int i = 0; i < n; i++) { if(a[i] > 0) { if(M[a[i]] != M1[-a[i]]) { ok = 1; } } } if(ok) { return - 1; } vector<int> izracunao(n, 0); int ans = 0; for(int i = 0; i < n; i++) { if(izracunao[i]) { continue; } if(a[i] > 0) { int idx = - 1; for(int j = i + 1; j < n; j++) { if(izracunao[j]) { continue; } if(a[i] == - a[j]) { idx = j; break; } } ans += idx - i; izracunao[idx] = 1; //cout << "1 :::" << i << " " << idx << "\n"; } else { int idx = - 1; for(int j = i; j < n; j++) { if(izracunao[j]) { continue; } if(a[i] == - a[j]) { idx = j; break; } } ans += idx - i - 1; izracunao[idx] = 1; //cout << "2 :::" << i << " " << idx << "\n"; } } return ans; } /* int main() { cout << count_swaps({- 2, 2, 2, - 2, - 2, 2}); }*/
#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...