이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |