# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
225228 | MKopchev | Coin Collecting (JOI19_ho_t4) | C++14 | 95 ms | 4984 KiB |
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;
const int nmax=2e5+42;
int seen[nmax][3];
int active[3];
int main()
{
long long output=0;
int n,x,y;
scanf("%i",&n);
for(int i=1;i<=2*n;i++)
{
scanf("%i%i",&x,&y);
if(x>n){output+=x-n;x=n;}
if(x<1){output+=1-x;x=1;}
if(y>2){output+=y-2;y=2;}
if(y<1){output+=1-y;y=1;}
seen[x][y]++;
}
for(int i=1;i<=n;i++)
{
active[1]+=seen[i][1]-1;
active[2]+=seen[i][2]-1;
if(active[1]>0&&active[2]<0)
{
int add=min(active[1],-active[2]);
active[1]-=add;
active[2]+=add;
output+=add;
}
if(active[1]<0&&active[2]>0)
{
int add=min(-active[1],active[2]);
active[1]+=add;
active[2]-=add;
output+=add;
}
output+=abs(active[1])+abs(active[2]);
}
printf("%lld\n",output);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |