제출 #486805

#제출 시각아이디문제언어결과실행 시간메모리
486805HaidaraArranging Shoes (IOI19_shoes)C++17
10 / 100
6 ms9712 KiB
#include<bits/stdc++.h> #include<shoes.h> #define rep(i,x,n) for(int i=(x);i<(n);i++) #define FOR(i,n) rep(i,0,n) #define v(i) vector< i > #define ll long long using namespace std; const ll inf=1LL<<62LL; const ll mod=1e9+7; const ll maxn=100200; ll count_swaps(v(int)a) { ll ans=0; ll n=a.size(); set<int>posl[maxn],posr[maxn]; FOR(i,n) if(a[i]<0) posl[-a[i]].insert(i); else posr[a[i]].insert(i); v(bool)vis(maxn,0); FOR(i,n) { if(vis[i]) continue; if(a[i]>0) { ans++; auto it=posl[a[i]].end(); it--; vis[*it]=1; vis[*posr[a[i]].begin()]=1; ans+=(abs(*it-*posr[a[i]].begin())-1); posr[a[i]].erase(posr[a[i]].begin()); posl[a[i]].erase(it); } else { a[i]=abs(a[i]); auto it=posr[a[i]].end(); it--; vis[*it]=1; vis[*posl[a[i]].begin()]=1; ans+=(abs(*it-*posl[a[i]].begin())-1); posl[a[i]].erase(posl[a[i]].begin()); posr[a[i]].erase(it); } } 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...