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 task "D"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 5;
int n;
int a[MAXN][3];
ll ans = 0;
void Input()
{
cin >> n;
for (int i = 1; i <= 2 * n; i++)
{
int x, y;
cin >> x >> y;
int x1 = x, y1 = y;
if (x < 1)
x1 = 1;
else
if (x > n)
x1 = n;
if (y < 1)
y1 = 1;
else
if (y > 2)
y1 = 2;
ans += abs(x1 - x);
ans += abs(y1 - y);
a[x1][y1]++;
}
}
void Solve()
{
int d1 = 0, d2 = 0;
for (int i = 1; i <= n; i++)
{
d1 += a[i][1] - 1;
d2 += a[i][2] - 1;
while (d1 > 0 && d2 < 0)
{
ans++;
d1--;
d2++;
}
while (d1 < 0 && d2 > 0)
{
ans++;
d1++;
d2--;
}
ans += abs(d1) + abs(d2);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
Input();
Solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |