#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 100000
int n, t[N+1];
array<int, 2> a[N<<1];
i64 z;
int main()
{
ShinLena;
cin >> n;
for (int i = 0; i < 2*n; ++i) cin >> a[i][0] >> a[i][1];
sort(a, a+2*n);
for (int i = 1; i <= n; ++i) t[i] = 3;
for (int l = 1, i = 0; i < 2*n; ++i)
{
int ty = -1, X = 1e9;
for (int j : {0, 1})
if (t[l] & (1 << j))
if (abs(a[i][1] - j) < X) X = abs(a[i][1] - j), ty = j;
z += abs(l - a[i][0]) + abs(ty - a[i][1]);
t[l] &= ~(1 << ty);
if (!t[l]) ++l;
}
cout << z;
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 |
- |