Submission #416536

# Submission time Handle Problem Language Result Execution time Memory
416536 2021-06-02T15:02:59 Z idk321 Sky Walking (IOI19_walk) C++17
33 / 100
352 ms 73024 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);
        }
    }

    ll res = INF;
    for (int i : startsAt[0])
    {
        res = min(res, dp[i] + y[i]);
    }

    if (res == INF) return -1;
    return res + 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++)
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 50380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 50388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 81 ms 55412 KB Output is correct
2 Correct 176 ms 58712 KB Output is correct
3 Correct 210 ms 59980 KB Output is correct
4 Correct 261 ms 70088 KB Output is correct
5 Correct 352 ms 70868 KB Output is correct
6 Correct 294 ms 71160 KB Output is correct
7 Correct 145 ms 64708 KB Output is correct
8 Correct 227 ms 72832 KB Output is correct
9 Correct 273 ms 72604 KB Output is correct
10 Correct 176 ms 69496 KB Output is correct
11 Correct 46 ms 54236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 55412 KB Output is correct
2 Correct 176 ms 58712 KB Output is correct
3 Correct 210 ms 59980 KB Output is correct
4 Correct 261 ms 70088 KB Output is correct
5 Correct 352 ms 70868 KB Output is correct
6 Correct 294 ms 71160 KB Output is correct
7 Correct 145 ms 64708 KB Output is correct
8 Correct 227 ms 72832 KB Output is correct
9 Correct 273 ms 72604 KB Output is correct
10 Correct 176 ms 69496 KB Output is correct
11 Correct 46 ms 54236 KB Output is correct
12 Correct 209 ms 59952 KB Output is correct
13 Correct 292 ms 69960 KB Output is correct
14 Correct 305 ms 70848 KB Output is correct
15 Correct 203 ms 68284 KB Output is correct
16 Correct 225 ms 68800 KB Output is correct
17 Correct 199 ms 68676 KB Output is correct
18 Correct 217 ms 68348 KB Output is correct
19 Correct 201 ms 68756 KB Output is correct
20 Correct 178 ms 65092 KB Output is correct
21 Correct 62 ms 58700 KB Output is correct
22 Correct 167 ms 67012 KB Output is correct
23 Correct 198 ms 67416 KB Output is correct
24 Correct 196 ms 67916 KB Output is correct
25 Correct 167 ms 67376 KB Output is correct
26 Correct 173 ms 68952 KB Output is correct
27 Correct 321 ms 71400 KB Output is correct
28 Correct 253 ms 69996 KB Output is correct
29 Correct 294 ms 70992 KB Output is correct
30 Correct 129 ms 64584 KB Output is correct
31 Correct 307 ms 72384 KB Output is correct
32 Correct 158 ms 68608 KB Output is correct
33 Correct 167 ms 70424 KB Output is correct
34 Correct 198 ms 70756 KB Output is correct
35 Correct 196 ms 70104 KB Output is correct
36 Correct 192 ms 69572 KB Output is correct
37 Correct 196 ms 68376 KB Output is correct
38 Correct 178 ms 72204 KB Output is correct
39 Correct 208 ms 73024 KB Output is correct
40 Correct 187 ms 70824 KB Output is correct
41 Correct 188 ms 69204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 50380 KB Output isn't correct
2 Halted 0 ms 0 KB -