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 all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
ll n, x, y, ans, cnt[NMAX][2], a, b, t;
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 0; i < 2 * n; i++){
cin >> x >> y;
if(x < 1) ans += 1 - x, x = 1;
else if(x > n) ans += x - n, x = n;
if(y >= 2) ans += y - 2, y = 1;
else ans += 1 - y, y = 0;
cnt[x][y]++;
}
for(int i = 1; i <= n; i++){
a += cnt[i][0] - 1;
b += cnt[i][1] - 1;
if(a * b < 0){
if(a > 0){
t = min(a, -b);
a -= t; b += t; ans += t;
}
else{
t = min(-a, b);
b -= t, a += t, ans += t;
}
}
ans += abs(a + b);
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |