이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |