This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 06.07.2022 12:06:17
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> x(2 * n), y(2 * n);
for (int i = 0; i < 2 * n; i++) {
cin >> x[i] >> y[i];
}
long long ans = 0;
vector<vector<int>> cnt(n, vector<int>(2));
for (int i = 0; i < 2 * n; i++) {
if (x[i] < 1) {
ans += 1 - x[i];
x[i] = 1;
}
if (y[i] < 1) {
ans += 1 - y[i];
y[i] = 1;
}
if (x[i] > n) {
ans += x[i] - n;
x[i] = n;
}
if (y[i] > 2) {
ans += y[i] - 2;
y[i] = 2;
}
cnt[x[i] - 1][y[i] - 1] += 1;
}
int L = 0, R = 0;
for (int i = 0; i < n; i++) {
L += cnt[i][0] - 1;
R += cnt[i][1] - 1;
while (L < 0 && R > 0) {
ans += 1;
L += 1;
R -= 1;
}
while (R < 0 && L > 0) {
ans += 1;
R += 1;
L -= 1;
}
ans += abs(L) + abs(R);
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |