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 long long
using namespace std;
const int INF = 2e18;
const int MAXN = 1e5 + 1;
int nbOcc[MAXN][3];
int delta[3];
signed main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int nbPieces;
cin >> nbPieces;
int sol(0);
for (int i = 0; i < 2*nbPieces; ++i)
{
int x, y;
cin >> x >> y;
int oldX(x), oldY(y);
if (x < 1) x = 1;
else if (x > nbPieces) x = nbPieces;
if (y < 1) y = 1;
else if (y > 2) y = 2;
sol += abs(x-oldX)+ abs(y-oldY);
nbOcc[x][y]++;
}
for (int x(1); x <= nbPieces; ++x)
{
sol += abs(delta[1]) + abs(delta[2]);
for (int y(1); y <= 2; ++y)
delta[y] += 1 - nbOcc[x][y];
if (delta[1] * delta[2] < 0)
{
int t= delta[1] < 0 ? min(delta[2], -delta[1]) : min(delta[1], -delta[2]);
sol += t;
if (delta[1] < 0)
delta[2] -= t, delta[1] += t;
else
delta[2] += t, delta[1] -= t;
}
}
cout << sol << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |