Submission #301882

#TimeUsernameProblemLanguageResultExecution timeMemory
301882NicolaAbusaad2014Arranging Shoes (IOI19_shoes)C++14
10 / 100
1053 ms27512 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { map<long,vector<long> >m; map<long,long>now; map<long,bool>ok; long n=s.size(); long long arr[n]={},x,z,ans=0; for(long i=0;i<n;i++){ m[s[i]].push_back(i); } for(long i=0;i<n;i++){ if(ok[abs(s[i])]){ ok[abs(s[i])]=false; } else{ ok[abs(s[i])]=true; z=now[abs(s[i])]; x=m[-s[i]][z]; now[abs(s[i])]++; for(long j=x+1;j<n;j++){ arr[j]--; } ans+=x+arr[x]-i-arr[i]-1; if(s[i]>0){ ans++; } } } 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...