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 int ll
//{ PXH612
using namespace std;
#define ll long long
#define db double
#define pp pair<int,int>
#define x first
#define y second
#define false(x) if(!(x))
template<typename A,typename B>bool Min(A &a,B b){if(a<=b) return 0;a=b;return 1;}
template<typename A,typename B>bool Max(A &a,B b){if(a>=b) return 0;a=b;return 1;}
#define in ({ll x=0;int o=0,c=char(),t=0;for(;!isdigit(c)&&t<1000;c=getchar(),t++) o=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';o?-x:x;})
#define inchar ({char c=getchar();while(c==' '||c=='\n') c=getchar();c;})
#define FOR(i,a,b) for(int i=a,ENDFOR=b;i<=ENDFOR;i++)
#define ROF(i,a,b) for(int i=b,ENDFOR=a;ENDFOR<=i;i--)
#define RR(x,a,b) {cout<<#x<<": ";FOR(_,a,b) cout<<x[_]<<" ";cout<<"\n";}
#define rr(x) " "<<#x<<'='<<(x)<<" "
#define VEC(i,a) for(auto&i:a)
#define pb push_back
#define vn(a) (int)a.size()-1
#define bit(x,i) ((x>>(i-1))&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
#define mu(x) (1ll<<x)
#define bitnum(x) __builtin_popcountll(x)
#define segg(a,b) (abs(a-b)+1)
#define midd(a,b) (a+(b-(a))/2)
#define mems(x,a) memset(x,a,sizeof x)
#define open(a) freopen(a,"r",stdin)
#define shut(b) freopen(b,"w",stdout)
//}/////////////////////////////////////////////////////}
const int N=1e5+5;
int n;
ll res=0;
int f[N][5];
int d[N][5];
int sum[5];
main()
{
// open("coin.inp");
// shut("coin.out");
n=in;
FOR(i,1,n*2)
{
int x=in,y=in;
int X=x,Y=y;
Max(X,1);Min(X,n);
Max(Y,1);Min(Y,2);
res+=abs(x-X)+abs(y-Y);
f[X][Y]++;
}
FOR(i,1,n)
{
// cout<<"=================" rr(i) "\n";
FOR(ud,1,2) res+=abs(sum[ud]);
FOR(ud,1,2) sum[ud]+=f[i][ud]-1;
while(sum[1]>0&&sum[2]<0)
{
sum[1]--;
sum[2]++;
res++;
}
while(sum[1]<0&&sum[2]>0)
{
sum[1]++;
sum[2]--;
res++;
}
//assert(sum[1]<0);
// assert(sum[1]<0);
}
cout<<res;
}
Compilation message (stderr)
joi2019_ho_t4.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
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... |