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 <bits/stdc++.h>
using namespace std;
#define int long long
int n, a[100010][2], b[2];
main(){
cin >> n; int ans = 0;
for(int i = 0; i < 2*n; i++){
int x,y,X,Y; cin >> x >> y; X=x,Y=y;
x=clamp(x,1ll,n), y=clamp(y,1ll,2ll);
ans+=abs(X-x)+abs(Y-y); a[x][y-1]++;
}
for(int i = 1; i <= n; i++){
b[0]+=a[i][0]-1,b[1]+=a[i][1]-1;
for(int j : {0,1}){
int xd=min(abs(b[0]),abs(b[1]));
if(b[j]>0 and b[j^1]<0)
ans+=xd,b[j]-=xd,b[j^1]+=xd;
}
ans+=abs(b[0])+abs(b[1]);
}
cout << ans << "\n";
}
Compilation message (stderr)
joi2019_ho_t4.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |