# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
283545 | test2 | Arranging Shoes (IOI19_shoes) | C++14 | 1092 ms | 23276 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "shoes.h"
#define I inline void
using namespace std ;
using ll = long long ;
using ld = long double ;
const int N = 3000 + 7 , mod = 1e9 + 7 ;
// How interesting!
int n;
long long count_swaps(std::vector<int> s) {
map<int,vector<int> > mp ;
ll ret = 1e9 ;
vector<pair<int,int>> v ;
int pos = 0 ;
for(auto u : s){
if(mp[-u].size()){
v.push_back({mp[-u].back() , pos}) ;
mp[-u].pop_back() ;
}
else{
mp[u].push_back(pos) ;
}
pos ++ ;
}
int n = (int) s.size() ;
vector<int> per ;
for(int i = 0 ;i < n ;i ++){
per.push_back(i) ;
}
for(auto u : v){
//cout<< u.first <<" " << u.second <<"..\n" ;
}
do{
bool bad = 0 ;
ll ret1 = 0 ;
for(int i = 1 ;i < n;i+=2){
int x = s[per[i-1]] , y = s[per[i]] ;
if(!(x == -y && x < y)){
bad = 1;
break ;
}
ret1+= abs(i - per[i]) ;
ret1+= abs((i-1) - per[i-1]) ;
}
if(!bad){
ret = min(ret , ret1 / 2) ;
}
}
while(next_permutation(per.begin() , per.end())) ;
return ret;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |