#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define cd complex<double>
#define p_q priority_queue
using namespace std;
int main(){
AquA;
int n;
cin >> n;
vector<int> a(n,-1),b(n,-1);
long long ans=0;
for(int i=0;i<2*n;i++){
int x,y;
cin >> x >> y;
x--;
int c=max(0,min(x,n-1)),d=max(0,min(y,1));
ans+=abs(c-x)+abs(d-y);
if(y==0){
a[c]++;
}
else{
b[c]++;
}
}
int e=0,f=0;
for(int i=0;i<n;i++){
e+=a[i];
f+=b[i];
if(e>0 && f<0){
int y=min(abs(e),abs(f));
e-=y;
f+=y;
ans+=y;
}
else if(f>0 && e<0){
int y=min(abs(e),abs(f));
e+=y;
f-=y;
ans+=y;
}
ans+=abs(e);
ans+=abs(f);
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |