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>
using namespace std;
long long n,ps[2][100069],ca[6];
int main()
{
long long i,ii,jj,u,x,y,x2,y2,lb,rb,z=0;
scanf("%lld",&n);
for(i=1;i<=n*2;i++)
{
scanf("%lld%lld",&x,&y);
x2=min(max(x,1ll),n);
y2=min(max(y,1ll),2ll);
z+=abs(x-x2)+abs(y-y2);
ps[y2-1][x2]++;
}
for(ii=0;ii<2;ii++)
{
u=!ii*2-1;
for(i=1;i<=n;i++)
{
ps[ii][i]=ps[ii][i-1]+(ps[ii][i]-1)*u;
}
}
lb=0;
rb=0;
for(i=1;i<n;i++)
{
if(ps[0][i]>ps[1][i])
{
swap(ps[0][i],ps[1][i]);
}
z+=ps[1][i]-ps[0][i];
z+=max(ps[0][i]-rb,0ll)+max(lb-ps[1][i],0ll);
ca[0]=lb;
ca[1]=rb;
for(ii=0;ii<2;ii++)
{
for(jj=0;jj<2;jj++)
{
ca[2+ii*2+jj]=ps[jj][i];
}
}
sort(ca,ca+6);
lb=ca[2];
rb=ca[3];
}
z+=max(ps[0][n]-rb,0ll)+max(lb-ps[1][n],0ll);
printf("%lld\n",z);
}
Compilation message (stderr)
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%lld%lld",&x,&y);
| ~~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |