# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430259 | Nicholas_Patrick | Coin Collecting (JOI19_ho_t4) | C++17 | 63 ms | 1092 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 <queue>
#include <algorithm>
using namespace std;
int diff(int x, int y){
return x<y?y-x:x-y;
}
int ab(int x){
return x<0?-x:x;
}
struct point{
int x, y;
};
int main(){
int n;
scanf("%d", &n);
vector<int> top(n, -1), bot(n, -1);
long long ans=0;
for(int i=n*2; i--;){
int x, y;
scanf("%d%d", &x, &y);
if(y>2){
ans+=y-2;
y=2;
}
if(y<1){
ans+=1-y;
y=1;
}
if(x<1){
ans+=1-x;
x=1;
}
if(x>n){
ans+=x-n;
x=n;
}
if(y==2)
top[x-1]++;
else
bot[x-1]++;
}
for(int i=0; i<n; i++){
if(top[i]>=0){
if(bot[i]<0){
if(top[i]<-bot[i]){
ans+=top[i];
bot[i]+=top[i];
top[i]-=top[i];
}else{
ans-=bot[i];
top[i]+=bot[i];
bot[i]-=bot[i];
}
}
}else{
if(bot[i]>=0){
if(-top[i]<bot[i]){
ans-=top[i];
bot[i]+=top[i];
top[i]-=top[i];
}else{
ans+=bot[i];
top[i]+=bot[i];
bot[i]-=bot[i];
}
}
}
if(top[i]){
ans+=ab(top[i]);
top[i+1]+=top[i];
}
if(bot[i]){
ans+=ab(bot[i]);
bot[i+1]+=bot[i];
}
}
printf("%lld\n", 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... |