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() {
int n;
cin >> n;
vector<vector<bool>> used(n, vector<bool>(2, false));
vector<int> x(2 * n), y(2 * n);
for (int i = 0; i < 2 * n; i++) {
cin >> x[i] >> y[i];
x[i]--, y[i]--;
}
long long ans = 0;
for (int i = 0; i < 2 * n; i++) {
if (x[i] != INT_MIN && y[i] != INT_MIN) {
tuple<int, int, int> cur = {INT_MAX, INT_MAX, INT_MAX};
for (int j = 0; j < n; j++) {
for (int k = 0; k < 2; k++) {
if (!used[j][k]) {
cur = min(cur, {abs(x[i] - j) + abs(y[i] - k), j, k});
}
}
}
used[get<1>(cur)][get<2>(cur)] = true;
ans += get<0>(cur);
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |