#include <bits/stdc++.h>
#define int long long
using namespace std;
const int nmax = 3e5 + 1;
int f[nmax][3];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, ans = 0;
cin >> n;
/*
for(int i=1; i<=(n<<1); ++i){
int x, y;
cin >> x >> y;
if(x < 1) ans += 1 - x, x = 1;
else if(x > n) ans += x - n, x = n;
if(y < 1) ans += 1 - y, y = 1;
else if(y > 2) ans += y - 2, y = 2;
++f[x][y];
}
*/
for(int i = 1; i <= 2 * n; i ++) {
int a, b;
cin >> a >> b;
//cout << i << " ";
// punem in cel mai apropiat loc
if(a < 1) {
//cout << "b mai mic ";
ans += 1 - a;
a = 1;
} else if(a > n) {
//cout << "b mai mare ";
ans += a - n;
a = n;
}
if(b < 1) {
//cout << "a mai mic ";
ans += 1 - b;
b = 1;
} else if(b > 2) {
//cout << "a mai mare ";
ans += b - 2;
b = 2;
}
//cout << endl;
f[a][b] ++;
}
for(int i = 1; i <= n; i ++){
int a = f[1][i] - 1, b = f[2][i] - 1;
while(a > 0 && b < 0) {
a --;
b ++;
ans ++;
}
while(a < 0 && b > 0) {
a ++;
b --;
ans ++;
}
ans += abs(a) + abs(b);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |