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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<>,
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
#define ll long long
#define ii pair<ll,ll>
#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif
const ll inf=1e15;
const ll maxn=1e5+5;
const ll mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll arr[maxn][3];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,x,y,ans=0;
cin>>n;
for (int i=1;i<=2*n;i++){
cin>>x>>y;
if (x<=1 && y<=1) arr[1][1]++, ans+=abs(1-x)+abs(1-y);
else if (1<x && x<n && y<=1) arr[x][1]++, ans+=abs(1-y);
else if (x>=n && y<=1) arr[n][1]++, ans+=abs(n-x)+abs(1-y);
else if (x<=1 && y>=2) arr[1][2]++, ans+=abs(1-x)+abs(2-y);
else if (1<x && x<n && y>=2) arr[x][2]++, ans+=abs(2-y);
else if (x>=n && y>=2) arr[n][2]++, ans+=abs(n-x)+abs(2-y);
}
ll tot1=0,tot2=0;
for (int i=1;i<=n;i++){
tot1+=arr[i][1];
tot2+=arr[i][2];
tot1--,tot2--;
while (tot1<0 && tot2>0) tot1++,tot2--,ans++;
swap(tot1,tot2);
while (tot1<0 && tot2>0) tot1++,tot2--,ans++;
ans+=abs(tot1)+abs(tot2);
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |