#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<int,pii>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
void solve(){
int n;
cin >> n;
pii arr[2*n];
vector<pii>cur;
for(int x=1;x<=n;x++){
for(int y=1;y<=2;y++) cur.push_back({x,y});
}
vector<pair<int,pii>>v;
for(int x=0;x<2*n;x++){
cin >> arr[x].first >> arr[x].second;
for(int y=0;y<2*n;y++){
v.push_back({abs(arr[x].first-cur[y].first)+abs(arr[x].second-cur[y].second),{x,y}});
}
}
sort(v.begin(),v.end());
bool visited[2][2*n+5];
memset(visited,0,sizeof(visited));
int counter=0;
for(auto it:v){
if(!visited[0][it.second.first]&&!visited[1][it.second.second]){
counter+=it.first;
visited[0][it.second.first]=true;
visited[1][it.second.second]=true;
}
}
cout << counter;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("in.txt","r",stdin);
//freopen("in.txt","w",stdout);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |