Submission #208332

#TimeUsernameProblemLanguageResultExecution timeMemory
208332alexxela12345Arranging Shoes (IOI19_shoes)C++17
50 / 100
1098 ms24568 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll count_swaps(vector<int> a) { int n = a.size() / 2; ll ans = 0; map<int, vector<int>> last; vector<int> pr(2 * n, -1); for (int i = 2 * n - 1; i >= 0; i--) { last[a[i]].push_back(i); } for (int i = 0; i < 2 * n; i++) { if (pr[i] != -1) continue; pr[i] = last[-a[i]].back();; last[-a[i]].pop_back(); last[a[i]].pop_back(); ans += abs(pr[i] - i) - 1; if ((pr[i] > i) != (a[pr[i]] > a[i])) { ans++; } pr[pr[i]] = i; } for (int i = 0; i < 2 * n; i++) { if (pr[i] > i) { for (int j = i + 1; j < pr[i]; j++) { if (pr[j] > pr[i]) { ans--; } } } } 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...