답안 #172993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172993 2020-01-03T00:07:32 Z tri Sky Walking (IOI19_walk) C++14
0 / 100
21 ms 3064 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

const int MAXN = 1e5 + 10;

int N, M;

vi l, r, y, cost;

ll min_distance(vi x, vi h, vi iL, vi iR, vi iY, int s, int g) {
    N = x.size();
    M = l.size();

    priority_queue<pi, vector<pi>, greater<pi>> start;
    priority_queue<pi, vector<pi>, greater<pi>> end;

    l = iL;
    r = iR;
    y = iY;

    cost.resize(M + 2, 1e9);

    for (int i = 0; i < M; i++) {
        start.push({l[i], i});
        end.push({r[i], i});
    }

    l.pb(0);
    r.pb(0);
    cost[M] = 0;

    end.push({0, M});

    bool sameH = true;

    int h0 = h[0];
    for (int i = 1; i < N; i++) {
        if (h[i] != h0) {
            sameH = false;
            break;
        }
    }

    if (s == 0 && g == N - 1 && sameH) {
        set<pi> active;

        for (int i = 0; i < N; i++) {
            while (end.top().f < i) {
                pi tR = end.top();
                end.pop();
                active.erase({y[tR.s], tR.s});
            }

            if (active.size() == 0) {
                return -1;
            }

            while (start.top().f == i) {
                pi tI = start.top();
                start.pop();
                int cBridge = tI.s;

                pi cP = {y[cBridge], cBridge};
                auto above = active.lower_bound(cP);

                int bestC = 1e9;
                if (above != active.end()) {
                    int pBridge = (*above).s;
                    bestC = min(bestC, cost[pBridge] + x[i] - l[pBridge] + abs(y[pBridge] - y[cBridge]));
                }

                if (above != active.begin()) {
                    auto below = --above;
                    int pBridge = (*below).s;
                    bestC = min(bestC, cost[pBridge] + x[i] - l[pBridge] + abs(y[pBridge] - y[cBridge]));
                }

                active.insert(cP);
                cost[tI.s] = bestC;
            }
        }

        int fBridge = (*active.begin()).s;
        int ans = cost[fBridge] + x[N - 1] - l[fBridge] + y[fBridge];
        return ans;
    } else {

        return -1;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 3064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 3064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -