답안 #823851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823851 2023-08-13T08:45:32 Z vjudge1 Sky Walking (IOI19_walk) C++17
0 / 100
2980 ms 163536 KB
#include "walk.h"

#include <bits/stdc++.h>

using namespace std;

long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
    vector<int> A = h, B = h;
    for (int i = s + 1; i < A.size(); i++) {
        A[i] = max(A[i - 1], A[i]);
    }
    for (int i = s - 1; i >= 0; i--) {
        A[i] = max(A[i + 1], A[i]);
    }
    for (int i = g + 1; i < B.size(); i++) {
        B[i] = max(B[i - 1], B[i]);
    }
    for (int i = g - 1; i >= 0; i--) {
        B[i] = max(B[i + 1], B[i]);
    }

    int m = 0;
/*
    int m = l.size();
    for (int i = 0; i < m; i++) {
        auto get = [&](int x, vector<int> &v, int h) -> tuple<int, int> {
            int l = x, r = v.size() - 1;
            while (l < r) {
                int m = (l + r) / 2;
                if (v[m] >= h) {
                    r = m;
                } else {
                    l = m + 1;
                }
            }
            int B = l;

            l = 0, r = x;
            while (l < r){
                int m = (l + r) / 2;
                if (v[m + 1] >= h) {
                    l = m + 1;
                } else {
                    r = m;
                }
            }
            return {l, B};
        };

        vector<int> v = {l[i], r[i]};
        if (l[i] < s && s < r[i]) {
            auto [x, y2] = get(s, A, y[i]);
            v.push_back(x);
            v.push_back(y2);
        }
        if (l[i] < g && g < r[i]) {
            auto [x, y2] = get(g, B, y[i]);
            v.push_back(x);
            v.push_back(y2);
        }
        sort(v.begin(), v.end());
        for (int j = 1; j < v.size(); j++) {
            if (v[j] != v[j - 1]) {
                l.push_back(v[j - 1]);
                r.push_back(v[j]);
                y.push_back(y[i]);
            }
        }
    }
*/

    long long inf = 1e18;
    vector<map<int, long long>> d(x.size());
    vector<map<int, vector<pair<int, int>>>> V(x.size());
    unordered_map<int, vector<int>> id;

    for (int i = 0; i < x.size(); i++) {
        d[i][0] = inf;
    }
    vector<vector<int>> gg;
    for (int i = m; i < l.size(); i++) {
        gg.push_back({l[i], y[i]});
        gg.push_back({r[i], y[i]});
        gg.push_back({l[i], -1, y[i]});
        gg.push_back({r[i] + 1, -2, y[i]});
    }
    sort(gg.begin(), gg.end());

    multiset<int> S;
    for (auto& shit: gg) {
        if (shit[1] == -1) {
            S.insert(shit[2]);
        } else if (shit[1] == -2) {
            S.erase(S.find(shit[2]));
        } else {
            d[shit[0]][shit[1]] = inf;
            auto p = S.lower_bound(shit[1]);
            if (p != S.begin()) {
                p--;
                d[shit[0]][*p] = inf;
            }
        }
    }

    d[s][0] = 0;

    for (int i = 0; i < x.size(); i++) {
        int last = 0;
        for (auto p: d[i]) {
            id[p.first].push_back(i);
            if (p.first == last) {
                continue;
            }
            //cout << i << " " << p.first << " " << i << " " << last << "\n";
            V[i][p.first].push_back({i, last});
            V[i][last].push_back({i, p.first});
            last = p.first;
        }
    }
    unordered_map<int, vector<int>> sid = id;
    for (auto&p : sid) {
        for (int j = 0; j < p.second.size(); j++) {
            p.second[j] = 0;
        }
        p.second.push_back(0);
    }
    for (int i = m; i < l.size(); i++) {
        // l[i], r[i]
        sid[y[i]][lower_bound(id[y[i]].begin(), id[y[i]].end(), l[i]) - id[y[i]].begin()]++;
        sid[y[i]][lower_bound(id[y[i]].begin(), id[y[i]].end(), r[i]) - id[y[i]].begin()]--;
    }
    //cout << "L ";
    //for (int i: id[5]) {
    //    cout << i << " ";
    //}
    //cout << "\n";
    for (auto&p : id) {
        auto shit = sid[p.first];
        for (int j = 0; j + 1 < shit.size(); j++) {
            shit[j + 1] += shit[j];
            if (shit[j]) {
                //cout << p.second[j] << " " << p.first << " " << p.second[j + 1] << " " << p.first << "\n";
                V[p.second[j]][p.first].push_back({p.second[j + 1], p.first});
                V[p.second[j + 1]][p.first].push_back({p.second[j], p.first});
            }
        }
    }

    auto dist = [&](int x1, int y1, int x2, int y2) -> long long {
        return (long long)abs(x[x1] - x[x2]) + abs(y1 - y2);
    };

    set<pair<int, pair<int, int>>> f;
    f.insert({0, {s, 0}});
    while (!f.empty()) {
        int a = f.begin()->second.first;
        int b = f.begin()->second.second;
        f.erase(f.begin());
        for (auto to: V[a][b]) {
            int na = to.first, nb = to.second;
            if (d[a][b] + dist(a, b, na ,nb) < d[na][nb]) {
                f.erase({d[na][nb], {na, nb}});
                d[na][nb] = d[a][b] + dist(a, b, na ,nb);
                f.insert({d[na][nb], {na, nb}});
            }
        }
    }

    return d[g][0];
}

Compilation message

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:9:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = s + 1; i < A.size(); i++) {
      |                         ~~^~~~~~~~~~
walk.cpp:15:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = g + 1; i < B.size(); i++) {
      |                         ~~^~~~~~~~~~
walk.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i = 0; i < x.size(); i++) {
      |                     ~~^~~~~~~~~~
walk.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int i = m; i < l.size(); i++) {
      |                     ~~^~~~~~~~~~
walk.cpp:107:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     for (int i = 0; i < x.size(); i++) {
      |                     ~~^~~~~~~~~~
walk.cpp:122:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |         for (int j = 0; j < p.second.size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
walk.cpp:127:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |     for (int i = m; i < l.size(); i++) {
      |                     ~~^~~~~~~~~~
walk.cpp:139:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |         for (int j = 0; j + 1 < shit.size(); j++) {
      |                         ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 27588 KB Output is correct
2 Correct 1301 ms 130648 KB Output is correct
3 Correct 1141 ms 134784 KB Output is correct
4 Correct 1200 ms 158756 KB Output is correct
5 Correct 2980 ms 163536 KB Output is correct
6 Correct 1359 ms 155448 KB Output is correct
7 Correct 550 ms 92124 KB Output is correct
8 Correct 477 ms 111712 KB Output is correct
9 Correct 1810 ms 151976 KB Output is correct
10 Correct 447 ms 101864 KB Output is correct
11 Incorrect 17 ms 10068 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 27588 KB Output is correct
2 Correct 1301 ms 130648 KB Output is correct
3 Correct 1141 ms 134784 KB Output is correct
4 Correct 1200 ms 158756 KB Output is correct
5 Correct 2980 ms 163536 KB Output is correct
6 Correct 1359 ms 155448 KB Output is correct
7 Correct 550 ms 92124 KB Output is correct
8 Correct 477 ms 111712 KB Output is correct
9 Correct 1810 ms 151976 KB Output is correct
10 Correct 447 ms 101864 KB Output is correct
11 Incorrect 17 ms 10068 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -