# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
121290 | imyujin | Coin Collecting (JOI19_ho_t4) | C++14 | 60 ms | 4984 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<stdio.h>
#include<algorithm>
using namespace std;
#define MAXN 100005
using namespace std;
typedef long long lint;
lint X[2*MAXN], Y[2*MAXN];
int S[2*MAXN][3];
int main(){
int N;
lint ans=0;
scanf("%d", &N);
for(int i=0; i<2*N; i++) scanf("%lld%lld", X+i, Y+i);
for(int i=0; i<2*N; i++){
int x, y;
if(X[i]<=0) x=1;
else if(X[i]>N) x=N;
else x=X[i];
y=Y[i]>=2?2:1;
ans+=abs(X[i]-x)+abs(Y[i]-y);
S[x][y]++;
//printf("(%d, %d)\n", x, y);
}
for(int i=1; i<=N; i++){
S[i][1]--;
S[i][2]--;
//printf("[%d %d]\n", S[i][1], S[i][2]);
}
for(int i=1; i<=N; i++){
if((long long)S[i][1]*S[i][2]<0){
if(abs(S[i][1])>abs(S[i][2])){
ans+=abs(S[i][2]);
S[i][1]+=S[i][2];
S[i][2]=0;
}
else{
ans+=abs(S[i][1]);
S[i][2]+=S[i][1];
S[i][1]=0;
}
}
ans+=abs(S[i][1]);
ans+=abs(S[i][2]);
S[i+1][1]+=S[i][1];
S[i+1][2]+=S[i][2];
}
printf("%lld", ans);
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... |