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;
#define int long long
const int INF = 1e18 + 7;
signed main() {
int n;
cin >> n;
vector <pair <int, int> > a, b;
for (int i = 0; i < 2 * n; ++i) {
int x, y;
cin >> x >> y;
a.push_back({x, y});
}
for (int i = 1; i <= n; ++i) {
b.push_back({i, 1});
b.push_back({i, 2});
}
int ans = INF;
sort(a.begin(), a.end());
do {
int nn = 0;
for (int i = 0; i < 2 * n; ++i) {
nn += abs(a[i].first - b[i].first) + abs(a[i].second - b[i].second);
}
ans = min(ans, nn);
} while (next_permutation(a.begin(), a.end()));
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... |