# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
704102 | 1075508020060209tc | Coin Collecting (JOI19_ho_t4) | C++14 | 1 ms | 308 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.
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
pair<int,int>ar[500005];
int vsa[500005];
int vsb[500005];
signed main(){
cin>>n;
for(int i=1;i<=n+n;i++){
cin>>ar[i].X>>ar[i].Y;
}
vector<pair<int,pair<int,int>>>seq;
for(int j=1;j<=n;j++){
for(int i=1;i<=n+n;i++){
int cst=abs(ar[i].X-j)+abs(ar[i].Y-1);
seq.push_back({cst,{i,j}});
}
}
for(int j=1;j<=n;j++){
for(int i=1;i<=n+n;i++){
int cst=abs(ar[i].X-j)+abs(ar[i].Y-2);
seq.push_back({cst,{i,j+n}});
}
}
sort(seq.begin(),seq.end());
int ans=0;
for(int i=0;i<seq.size();i++){
if(vsa[seq[i].second.first]==0&&vsb[seq[i].second.second]==0){
ans+=seq[i].first;
}
}
cout<<ans<<endl;
}
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... |