Submission #867426

#TimeUsernameProblemLanguageResultExecution timeMemory
867426cheat_when_I_was_youngArranging Shoes (IOI19_shoes)C++17
10 / 100
0 ms348 KiB
#include "shoes.h" #include "bits/stdc++.h" using namespace std; long long count_swaps(vector<int> s) { int n = (int)s.size() / 2; vector<vector<int>> l(n+1, vector<int>()); vector<vector<int>> r(n+1, vector<int>()); long long ans = 0; for (int i = 0; i < (int)s.size(); ++i) { if (s[i] < 0) { s[i] = -s[i]; if (r[s[i]].size()) { ans += i - r[s[i]].back(); r[s[i]].pop_back(); } else l[s[i]].push_back(i); } else { if (l[s[i]].size()) { ans += i - l[s[i]].back() - 1; l[s[i]].pop_back(); } else r[s[i]].push_back(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...