//Pantyhose(black) + glasses = infinity
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "coincollecting"
const int MAX_N = 200002;
const int INF = 1e9;
int n, cnt[3][MAX_N];
int64_t res;
pair<int, int> a[MAX_N];
void read_input() {
cin >> n;
for (int i=1; i<=2*n; ++i)
cin >> a[i].second >> a[i].first;
}
void init() {
for (int i=1; i<=2*n; ++i) {
vector<int> p = {1, n};
if (0<a[i].second && a[i].second<=n)
p.push_back(a[i].second);
int d = INF;
for (int x=1; x<=2; ++x) {
for (auto y : p)
d = min(d, abs(a[i].first-x)+abs(a[i].second-y));
}
res += d;
for (int x=1; x<=2; ++x) {
for (auto y : p) {
if (d==abs(a[i].first-x)+abs(a[i].second-y)) {
++cnt[x][y];
break;
}
}
}
}
}
void solve() {
int u = 0, d = 0;
for (int i=1; i<=n; ++i) {
u += (cnt[1][i]-1);
d += (cnt[2][i]-1);
while (d>0 && u<0) {
--d;
++u;
++res;
}
while (d<0 && u>0) {
++d;
--u;
++res;
}
res = res + abs(u) + abs(d);
}
}
int main() {
#ifdef GLASSES_GIRL
freopen(FILE_NAME".in", "r", stdin);
// freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
read_input();
init();
solve();
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
356 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
356 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
356 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |