답안 #416551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416551 2021-06-02T15:18:01 Z idk321 Sky Walking (IOI19_walk) C++17
33 / 100
343 ms 70248 KB
#include "walk.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


const int M = 2000005;
const int N = 100005;
const ll INF = 2000000000000000000LL;
vector<int> adj[M];
vector<array<int, 2>> isAt[N];

int cnode = 0;
ll dp[N];


///usr/include/c++/10/bits/stl_heap.h|209|error: ‘bool Comparator::operator()(const std::__debug::array<long long int, 2>&, const std::__debug::array<long long int, 2>&) const’ is private within this context|

struct Comparator
{

    bool operator() (const array<ll, 2>& ar1, const array<ll, 2>& ar2) const
    {
        return tie(ar1[1], ar1[0]) < tie(ar2[1], ar2[0]);
    }
};

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<vector<int>> startsAt(x.size());
    vector<vector<int>> endsAt(x.size());

    for (int i = 0; i < l.size(); i++)
    {
        startsAt[l[i]].push_back(i);
        endsAt[r[i]].push_back(i);
    }


    multiset<array<int, 2>> sett;

    vector<int> in(y.size());
    for (int i = 0; i < x.size(); i++)
    {
        for (int j : endsAt[i])
        {
            sett.erase(sett.find({y[j], j}));
        }
        for (int j : startsAt[i])
        {
            sett.insert({y[j], j});
        }

        for (int j : endsAt[i])
        {
            auto it = sett.upper_bound({y[j], -1});
            if (it != sett.end())
            {
                adj[(*it)[1]].push_back(j);
                in[j]++;
            }
            if (it != sett.begin())
            {
                it--;
                adj[(*it)[1]].push_back(j);
                in[j]++;
            }
        }
    }

    for (int i = 0; i <N; i++) dp[i] = INF;


    for (int i : endsAt[x.size() - 1])
    {
        dp[i] = y[i];
    }

    vector<int> noIn;
    for (int i = 0; i < in.size(); i++)
    {
        if (in[i] == 0)
        {
            noIn.push_back(i);
        }
    }

    while (!noIn.empty())
    {
        int cur = noIn.back();
        noIn.pop_back();
        for (int next : adj[cur])
        {
            in[next]--;
            dp[next] = min(dp[cur] + abs(y[cur] - y[next]), dp[next]);
            if (in[next] == 0) noIn.push_back(next);
        }
    }


    int small = 2000000000;
    int ismall = -1;
    for (int i : startsAt[0])
    {
        if (y[i] < small)
        {
            small = y[i];
            ismall = i;
        }
    }

    if (ismall == -1 || dp[ismall] == INF) return -1;
    return dp[ismall] + y[ismall] + x.back() - x.front();
}

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:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 0; i < l.size(); i++)
      |                     ~~^~~~~~~~~~
walk.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < x.size(); i++)
      |                     ~~^~~~~~~~~~
walk.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int i = 0; i < in.size(); i++)
      |                     ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 50388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 50344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 54848 KB Output is correct
2 Correct 191 ms 56940 KB Output is correct
3 Correct 218 ms 57884 KB Output is correct
4 Correct 266 ms 66112 KB Output is correct
5 Correct 296 ms 66868 KB Output is correct
6 Correct 313 ms 67028 KB Output is correct
7 Correct 123 ms 61684 KB Output is correct
8 Correct 182 ms 68680 KB Output is correct
9 Correct 252 ms 68396 KB Output is correct
10 Correct 165 ms 65988 KB Output is correct
11 Correct 46 ms 53528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 54848 KB Output is correct
2 Correct 191 ms 56940 KB Output is correct
3 Correct 218 ms 57884 KB Output is correct
4 Correct 266 ms 66112 KB Output is correct
5 Correct 296 ms 66868 KB Output is correct
6 Correct 313 ms 67028 KB Output is correct
7 Correct 123 ms 61684 KB Output is correct
8 Correct 182 ms 68680 KB Output is correct
9 Correct 252 ms 68396 KB Output is correct
10 Correct 165 ms 65988 KB Output is correct
11 Correct 46 ms 53528 KB Output is correct
12 Correct 242 ms 58032 KB Output is correct
13 Correct 287 ms 65988 KB Output is correct
14 Correct 302 ms 66752 KB Output is correct
15 Correct 197 ms 64496 KB Output is correct
16 Correct 225 ms 64720 KB Output is correct
17 Correct 232 ms 64580 KB Output is correct
18 Correct 195 ms 64496 KB Output is correct
19 Correct 200 ms 64708 KB Output is correct
20 Correct 158 ms 62184 KB Output is correct
21 Correct 62 ms 56764 KB Output is correct
22 Correct 170 ms 63292 KB Output is correct
23 Correct 185 ms 63592 KB Output is correct
24 Correct 176 ms 64324 KB Output is correct
25 Correct 162 ms 63708 KB Output is correct
26 Correct 181 ms 65260 KB Output is correct
27 Correct 343 ms 67372 KB Output is correct
28 Correct 211 ms 65936 KB Output is correct
29 Correct 324 ms 66936 KB Output is correct
30 Correct 125 ms 61668 KB Output is correct
31 Correct 273 ms 68424 KB Output is correct
32 Correct 168 ms 65460 KB Output is correct
33 Correct 166 ms 67188 KB Output is correct
34 Correct 180 ms 67612 KB Output is correct
35 Correct 201 ms 66884 KB Output is correct
36 Correct 169 ms 66564 KB Output is correct
37 Correct 162 ms 65604 KB Output is correct
38 Correct 177 ms 68904 KB Output is correct
39 Correct 213 ms 70248 KB Output is correct
40 Correct 193 ms 67892 KB Output is correct
41 Correct 186 ms 66628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 50388 KB Output isn't correct
2 Halted 0 ms 0 KB -