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;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<vector<int>> cnt(n, vector<int>(2));
vector<int> f(2);
long long ans = 0;
for (int i = 0; i < 2 * n; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
if (x < 0) {
ans -= x;
x = 0;
} else if (x > n - 1) {
ans += x - n + 1;;
x = n - 1;
}
if (y < 0) {
ans -= y;
y = 0;
} else if (y > 1) {
ans += y - 1;
y = 1;
}
++cnt[x][y];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 2; ++j) {
f[j] += cnt[i][j] - 1;
}
for (int j = 0; j < 2; ++j) {
if (f[j] > 0 && f[j ^ 1] < 0) {
int cur = min(f[j], -f[j ^ 1]);
ans += cur;
f[j] -= cur;
f[j ^ 1] += cur;
}
}
for (int j = 0; j < 2; ++j) {
ans += abs(f[j]);
}
}
printf("%lld\n", ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |