# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128453 | dragonslayerit | Coin Collecting (JOI19_ho_t4) | C++14 | 2 ms | 376 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 <cstdio>
#include <algorithm>
#include <stdint.h>
struct Point{
int64_t x,y;
void read(){
scanf("%ld %ld",&x,&y);
}
bool operator<(Point p)const{
return x<p.x;
}
}ps[200005];
int main(){
int N;
scanf("%d",&N);
for(int i=0;i<N*2;i++){
ps[i].read();
}
std::sort(ps,ps+N*2);
int64_t cost=0;
for(int i=0;i<N*2;i++){
int64_t x=i/2+1;
cost+=std::abs(ps[i].x-x);
ps[i].x=x;
std::swap(ps[i].x,ps[i].y);
}
for(int i=0;i<N;i++){
std::sort(ps+i*2,ps+(i+1)*2);
cost+=std::abs(ps[i*2].x-1);
cost+=std::abs(ps[i*2+1].x-2);
}
printf("%ld\n",cost);
return 0;
}
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... |