#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MXN = 200005;
int N, n, ans, c[MXN][2];
pii a[MXN];
int DIS(pii &a, pii &b) {
return abs(a.first - b.first) + abs(a.second - b.second);
}
void PUT(int id) {
pii tr;
tr.second = (a[id].second >= 2 ? 2 : 1);
if (1 <= a[id].first && a[id].first <= n) tr.first = a[id].first;
else tr.first = (a[id].first < 1 ? 1 : n);
c[tr.first][tr.second - 1]++;
ans += DIS(tr, a[id]);
}
void SOLVE() {
int up = 0, down = 0;
for (int i = 1; i <= n; i++) {
up += c[i][1];
down += c[i][0];
}
ans += abs(n - up);
int left = 0, right = N;
for (int i = 1; i < n; i++) {
left += (c[i][0] + c[i][1]);
right -= (c[i][0] + c[i][1]);
ans += abs(i * 2 - left);
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
N = n * 2;
for (int i = 0; i < N; i++) {
cin >> a[i].first >> a[i].second;
PUT(i);
}
// for (int j = 1; j >= 0; j--) {
// for (int i = 1; i <= n; i++) {
// cout << c[i][j] << ' ';
// }
// cout << endl;
// }
SOLVE();
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |