Submission #453695

#TimeUsernameProblemLanguageResultExecution timeMemory
453695ponytailArranging Shoes (IOI19_shoes)C++17
10 / 100
145 ms137980 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){ int 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); } } return ans1 / 2 + ans2; }
#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...