Submission #584398

#TimeUsernameProblemLanguageResultExecution timeMemory
584398KrisjanisPArranging Shoes (IOI19_shoes)C++14
50 / 100
1090 ms147216 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pii; ll count_swaps(vector<int> s) { ll n = s.size(); map<ll,queue<ll>> m; for(ll i=0;i<n;i++) m[s[i]].push(i); set<ll> erased; ll res = 0; for(ll i=0;i<n;i++) { if(erased.count(i)) continue; m[s[i]].pop(); ll j = m[-s[i]].front(); m[-s[i]].pop(); res += j-i-1; if(s[i]>0) res++; for(ll k=i+1;k<j;k++) if(erased.count(k)) res--; erased.insert(i); erased.insert(j); } return res; }
#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...