Submission #296301

# Submission time Handle Problem Language Result Execution time Memory
296301 2020-09-10T13:21:08 Z SamAnd Sky Walking (IOI19_walk) C++17
24 / 100
4000 ms 457416 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 100005;

int n, m;

map<int, vector<int> > g[N];
set<pair<int, int> > c;
set<int> s[N];

pair<int, int> maxu[N * 4];
void ubd(int tl, int tr, int x, int y, int pos)
{
    if (tl == tr)
    {
        maxu[pos] = m_p(y, x);
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd(tl, m, x, y, pos * 2);
    else
        ubd(m + 1, tr, x, y, pos * 2 + 1);
    maxu[pos] = max(maxu[pos * 2], maxu[pos * 2 + 1]);
}

pair<int, int> qry(int tl, int tr, int l, int r, int pos)
{
    if (l > r)
        return m_p(-1, -1);
    if (tl == l && tr == r)
        return maxu[pos];
    int m = (tl + tr) / 2;
    return max(qry(tl, m, l, min(m, r), pos * 2),
               qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

struct ban
{
    pair<int, int> u;
    ll d;
    ban(){}
    ban(pair<int, int> u, ll d)
    {
        this->u = u;
        this->d = d;
    }
};
bool operator<(const ban& a, const ban& b)
{
    return a.d > b.d;
}

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 F)
{
    n = sz(x);
    m = sz(y);

    for (int i = 0; i < n; ++i)
        ubd(0, n - 1, i, h[i], 1);

    for (int i = 0; i < m; ++i)
    {
        vector<int> v;
        while (1)
        {
            pair<int, int> u = qry(0, n - 1, l[i], r[i], 1);
            if (u.fi < y[i])
                break;
            v.push_back(u.se);
            ubd(0, n - 1, u.se, -1, 1);
        }
        sort(all(v));
        for (int j = 0; j < sz(v); ++j)
        {
            s[v[j]].insert(y[i]);
            ubd(0, n - 1, v[j], h[v[j]], 1);
        }
        for (int j = 0; j < sz(v) - 1; ++j)
        {
            g[v[j]][y[i]].push_back(v[j + 1]);
            g[v[j + 1]][y[i]].push_back(v[j]);
        }
    }
    s[S].insert(0);
    s[F].insert(0);

    priority_queue<ban> q;
    q.push(ban(m_p(S, 0), 0));
    while (1)
    {
        ban t;
        do
        {
            if (q.empty())
                return -1;
            t = q.top();
            q.pop();
        } while (c.find(t.u) != c.end());
        c.insert(t.u);
        if (t.u == m_p(F, 0))
            return t.d;
        for (int i = 0; i < g[t.u.fi][t.u.se].size(); ++i)
        {
            ban h = ban(m_p(g[t.u.fi][t.u.se][i], t.u.se), t.d);
            h.d += abs(x[t.u.fi] - x[h.u.fi]);
            q.push(h);
        }
        auto it = s[t.u.fi].find(t.u.se);
        if (it != (--s[t.u.fi].end()))
        {
            ++it;
            ban h = ban(m_p(t.u.fi, *it), t.d + *it - t.u.se);
            q.push(h);
            --it;
        }
        if (it != s[t.u.fi].begin())
        {
            --it;
            ban h = ban(m_p(t.u.fi, *it), t.d + t.u.se - *it);
            q.push(h);
            ++it;
        }
    }
}

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:110:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         for (int i = 0; i < g[t.u.fi][t.u.se].size(); ++i)
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 8 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9856 KB Output is correct
6 Correct 8 ms 9856 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9856 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 6 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 9 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 6 ms 9728 KB Output is correct
3 Correct 1442 ms 122200 KB Output is correct
4 Correct 1979 ms 156416 KB Output is correct
5 Correct 997 ms 108792 KB Output is correct
6 Correct 944 ms 96852 KB Output is correct
7 Correct 1016 ms 109304 KB Output is correct
8 Correct 2249 ms 159840 KB Output is correct
9 Correct 1256 ms 114680 KB Output is correct
10 Correct 2920 ms 213140 KB Output is correct
11 Correct 824 ms 72620 KB Output is correct
12 Correct 582 ms 56388 KB Output is correct
13 Correct 2479 ms 192136 KB Output is correct
14 Correct 474 ms 45404 KB Output is correct
15 Correct 617 ms 56440 KB Output is correct
16 Correct 636 ms 58872 KB Output is correct
17 Correct 587 ms 59684 KB Output is correct
18 Correct 674 ms 60552 KB Output is correct
19 Correct 25 ms 12152 KB Output is correct
20 Correct 226 ms 34040 KB Output is correct
21 Correct 534 ms 58644 KB Output is correct
22 Correct 417 ms 49784 KB Output is correct
23 Correct 830 ms 70024 KB Output is correct
24 Correct 570 ms 59076 KB Output is correct
25 Correct 549 ms 58952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 238 ms 23516 KB Output is correct
2 Execution timed out 4112 ms 457416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 238 ms 23516 KB Output is correct
2 Execution timed out 4112 ms 457416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 8 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9856 KB Output is correct
6 Correct 8 ms 9856 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9856 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 6 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 9 ms 9856 KB Output is correct
18 Correct 6 ms 9728 KB Output is correct
19 Correct 6 ms 9728 KB Output is correct
20 Correct 1442 ms 122200 KB Output is correct
21 Correct 1979 ms 156416 KB Output is correct
22 Correct 997 ms 108792 KB Output is correct
23 Correct 944 ms 96852 KB Output is correct
24 Correct 1016 ms 109304 KB Output is correct
25 Correct 2249 ms 159840 KB Output is correct
26 Correct 1256 ms 114680 KB Output is correct
27 Correct 2920 ms 213140 KB Output is correct
28 Correct 824 ms 72620 KB Output is correct
29 Correct 582 ms 56388 KB Output is correct
30 Correct 2479 ms 192136 KB Output is correct
31 Correct 474 ms 45404 KB Output is correct
32 Correct 617 ms 56440 KB Output is correct
33 Correct 636 ms 58872 KB Output is correct
34 Correct 587 ms 59684 KB Output is correct
35 Correct 674 ms 60552 KB Output is correct
36 Correct 25 ms 12152 KB Output is correct
37 Correct 226 ms 34040 KB Output is correct
38 Correct 534 ms 58644 KB Output is correct
39 Correct 417 ms 49784 KB Output is correct
40 Correct 830 ms 70024 KB Output is correct
41 Correct 570 ms 59076 KB Output is correct
42 Correct 549 ms 58952 KB Output is correct
43 Correct 238 ms 23516 KB Output is correct
44 Execution timed out 4112 ms 457416 KB Time limit exceeded
45 Halted 0 ms 0 KB -