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>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fir first
#define sec second
#define pdd pair<double, double>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pmax pair<__int128, __int128>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1 , 0};
const int mxN=100010;
const int mxM=2500000;
const int mxK=105;
const int MOD=1000000007;
const ll INF=8000000000000000001;
int N;
pll A[2*mxN];
pll B[2*mxN];
ll ans;
ll myabs(ll a)
{
return a>0 ? a : -a;
}
bool cmp1(pll a, pll b)
{
return a.fir<b.fir;
}
bool cmp2(pll a, pll b)
{
return a.sec<b.sec;
}
int main()
{
gibon
cin >> N;
for(int i=0;i<2*N;i++) cin >> A[i].fir >> A[i].sec;
for(int i=0;i<2*N;i++) B[i].fir=i/2+1, B[i].sec=i%2+1;
sort(A, A+2*N, cmp1);
sort(B, B+2*N, cmp1);
for(int i=0;i<2*N;i++) ans+=myabs(A[i].fir-B[i].fir);
sort(A, A+2*N, cmp2);
sort(B, B+2*N, cmp2);
for(int i=0;i<2*N;i++) ans+=myabs(A[i].sec-B[i].sec);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |