This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct pack {
int x, y;
bool operator < (pack a) {
return make_pair(x, y) < make_pair(a.x, a.y);
}
};
const int N = 1e5 + 5;
int n, f[N][5], d[N][5], sum[N];
pack a[2 * N];
main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("tpa.txt", "r", stdin);
cin >> n;
for(int i = 1; i <= 2 * n; ++i) {
cin >> a[i].x >> a[i].y;
}
int ans = 0;
for(int i = 1; i <= 2 * n; ++i) {
int X, Y;
X = a[i].x, Y = a[i].y;
X = max(X, 1ll); X = min(X, n);
Y = max(Y, 1ll); Y = min(Y, 2ll);
ans += abs(a[i].x - X) + abs(a[i].y - Y);
f[X][Y]++;
}
for(int i = 1; i <= n; ++i) {
ans += abs(sum[1]);
ans += abs(sum[2]);
sum[1] += f[i][1] - 1;
sum[2] += f[i][2] - 1;
while(sum[1] > 0 && sum[2] < 0) {
sum[1]--; sum[2]++; ans++;
}
while(sum[1] < 0 && sum[2] > 0) {
sum[1]++; sum[2]--; ans++;
}
}
cout << ans;
}
Compilation message (stderr)
joi2019_ho_t4.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |