#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 |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Execution timed out |
1080 ms |
256 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Execution timed out |
1080 ms |
256 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Execution timed out |
1080 ms |
256 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |