제출 #873155

#제출 시각아이디문제언어결과실행 시간메모리
873155sleepntsheepCoin Collecting (JOI19_ho_t4)C++17
0 / 100
0 ms344 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...