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 mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("q.gir","r",stdin);
// freopen("q.cik","w",stdout);
int n,ans=0;
cin>>n;
vector<vector<int>> rect(3,vector<int>(n+1,-1));
for(int i=0;i<2*n;i++){
int x,y;
cin>>y>>x;
int X=x,Y=y;
if(x>2){
ans+=x-2;
X=2;
}
if(x<1){
ans+=1-x;
X=1;
}
if(y>n){
ans+=y-n;
Y=n;
}
if(y<1){
ans+=1-y;
Y=1;
}
rect[X][Y]++;
}
int cnt=0;
rect[1][0]=0;
rect[2][0]=0;
for(int i=1;i<=n;i++){
rect[1][i]+=rect[1][i-1];
rect[2][i]+=rect[2][i-1];
cnt+=abs(rect[1][i-1])+abs(rect[2][i-1]);
int& x=rect[1][i];
int& y=rect[2][i];
if(x>0&&y<0){
if(x>-y){
x+=y;
cnt-=y;
y=0;
}
else{
y+=x;
cnt+=x;
x=0;
}
}
else if(x<0&&y>0){
if(-x>y){
x+=y;
cnt+=y;
y=0;
}
else{
y+=x;
cnt-=x;
x=0;
}
}
}
cout<<ans+cnt;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |