# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153822 | arnold518 | Coin Collecting (JOI19_ho_t4) | C++14 | 71 ms | 5816 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int N;
int A[3][MAXN+10];
ll ans;
int main()
{
int i, j;
scanf("%d", &N);
for(i=1; i<=2*N; i++)
{
int x, y;
scanf("%d%d", &x, &y);
if(x<1) ans+=1-x, x=1;
if(x>N) ans+=x-N, x=N;
if(y<1) ans+=1-y, y=1;
if(y>2) ans+=y-2, y=2;
A[y][x]++;
}
for(i=1; i<N; i++)
{
if(A[1][i]<1 && A[2][i]>=1)
{
if(A[1][i]+A[2][i]>=2)
{
ans+=1-A[1][i];
A[2][i]-=1-A[1][i];
A[1][i]=1;
}
else
{
ans+=A[2][i]-1;
A[1][i]+=A[2][i]-1;
A[2][i]=1;
}
}
if(A[2][i]<1 && A[1][i]>=1)
{
if(A[1][i]+A[2][i]>=2)
{
ans+=1-A[2][i];
A[1][i]-=1-A[2][i];
A[2][i]=1;
}
else
{
ans+=A[1][i]-1;
A[2][i]+=A[1][i]-1;
A[1][i]=1;
}
}
if(A[1][i]>=1)
{
ans+=A[1][i]-1;
A[1][i+1]+=A[1][i]-1; A[1][i]=1;
}
else
{
ans+=1-A[1][i];
A[1][i+1]+=A[1][i]-1; A[1][i]=1;
}
if(A[2][i]>=1)
{
ans+=A[2][i]-1;
A[2][i+1]+=A[2][i]-1; A[2][i]=1;
}
else
{
ans+=1-A[2][i];
A[2][i+1]+=A[2][i]-1; A[2][i]=1;
}
}
ans+=abs(A[1][N]-1);
printf("%lld", ans);
}
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... |