# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
500778 | Khizri | Arranging Shoes (IOI19_shoes) | C++17 | 1086 ms | 4772 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 "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
const int mxn=1e5+5;
int color[mxn];
int funk(vector<int>arr,vector<pii>vt){
int a=0,b=1,ans=0;
for(int i=0;i<arr.size();i++){
ans+=abs(vt[arr[i]].F-a);
for(int j=0;j<vt.size();j++){
if(i==j) continue;
if(vt[j].F>=a&&vt[j].F<=vt[arr[i]].F){
vt[j].F++;
}
}
for(int j=0;j<vt.size();j++){
if(vt[j].S>=a&&vt[j].S<=vt[arr[i]].F){
vt[j].S++;
}
}
ans+=abs(vt[arr[i]].S-b);
for(int j=0;j<vt.size();j++){
if(vt[j].F>=b&&vt[j].F<=vt[arr[i]].S){
vt[j].F++;
}
}
for(int j=0;j<vt.size();j++){
if(i==j) continue;
if(vt[j].S>=b&&vt[j].S<=vt[arr[i]].S){
vt[j].S++;
}
}
a+=2,b+=2;
}
return ans;
}
long long count_swaps(vector<int> s) {
int n=s.size();
vector<pii>vt;
for(int i=0;i<n;i++){
if(color[i]) continue;
for(int j=i+1;j<n;j++){
if(!color[j]&&-s[i]==s[j]){
if(s[i]<0){
vt.pb({i,j});
}
else{
vt.pb({j,i});
}
color[i]=1;
color[j]=1;
break;
}
}
}
vector<int>v;
for(int i=0;i<n/2;i++){
v.pb(i);
}
int ans=1e7;
do{
ans=min(ans,funk(v,vt));
}while(next_permutation(all(v)));
return ans;
}
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... |