Submission #808637

#TimeUsernameProblemLanguageResultExecution timeMemory
808637KemalKArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms212 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long int ll; int n; long long count_swaps(std::vector<int> s) { n = s.size(); if (n == 2){ if (s[0] < 0){ return 0; } return 1; } map <int, vector<int>> pos_right; map <int, vector<int>> pos_left; for (int i = 0; i < n; i++){ if (s[i] > 0){ pos_right[s[i]].push_back(i); } else{ pos_left[s[i]].push_back(i); } } ll ans = 0; for (auto x: pos_right){ for (int i = 0; i < (int)x.second.size(); i++){ if (x.second[i] > pos_left[-x.first][i]){ ans += x.second[i] - pos_left[-x.first][i] - 1ll; } else{ ans += abs(x.second[i] - pos_left[-x.first][i]); } } } 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...