#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |