Submission #453735

#TimeUsernameProblemLanguageResultExecution timeMemory
453735ponytailArranging Shoes (IOI19_shoes)C++17
45 / 100
189 ms136916 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; typedef long long ll; int n; int inv(int x){ if(x<0) return -x; else if(x>n) return x - n; else return x + n; } ll count_swaps(vector<int> S){ ll ans1 = 0, ans2 = 0; n = S.size() / 2; queue<int> mp[2 * n + 2]; int nxt = 0; for(int i=0; i<2*n; i++) { if(mp[inv(S[i])].size()){ ans1 += abs(mp[inv(S[i])].front() - nxt) + abs(i - nxt - 1); ans2 += (S[i]<0); nxt += 2; mp[inv(S[i])].pop(); } else{ mp[inv(inv(S[i]))].push(i); } } for(int i=1; i<=2*n; i++){ while(mp[i].size()){ mp[i].pop(); } } ll ans3 = 0, ans4 = 0; nxt = 0; reverse(S.begin(), S.end()); for(int i=0; i<2*n; i++) { if(mp[inv(S[i])].size()){ ans3 += abs(mp[inv(S[i])].front() - nxt) + abs(i - nxt - 1); ans4 += (S[i]>0); nxt += 2; mp[inv(S[i])].pop(); } else{ mp[inv(inv(S[i]))].push(i); } } return min(ans1 / 2 + ans2, ans3 / 2 + ans4); }
#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...