답안 #906302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906302 2024-01-14T00:20:11 Z vjudge1 Sky Walking (IOI19_walk) C++17
0 / 100
4000 ms 1048576 KB
#include "walk.h"
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

struct info {
    ll l, r;
        ll height;

    info(ll l, ll r, ll height): l(l), r(r), height(height) {}
} ;

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) {
    ll n = x.size();
    // the only important heights, anyways
    vector<ll> yvalues(A(y)); yvalues.push_back(0);
    sort(A(yvalues));
    yvalues.erase(unique(A(yvalues)), yvalues.end());
    ll m = yvalues.size();

    vector<vl> dist(n, vl(m, 1e18));
    priority_queue<pair<ll, pl>, vector<pair<ll, pl>>, greater<>> pq;

    vector<info> skywalks;
    F(i, 0, y.size()) skywalks.emplace_back(l[i], r[i], y[i]);

    dist[s][0] = 0;
    pq.emplace(0, pair(s, 0));

    while (pq.size()) {
        auto [d, head] = pq.top(); pq.pop();
        auto [i, j] = head;

        if (d != dist[i][j]) continue;
        assert(yvalues[j] <= h[i]);
        
        vector<pair<ll, pl>> edges;
        F(nj, 0, m) if (yvalues[nj] <= h[i]) edges.emplace_back(abs(yvalues[j] - yvalues[nj]), pair(i, nj));

        if (j) for (auto &[l, r, height]: skywalks) if (yvalues[j] == height) {
            auto canreach = [&](ll i, ll j) {
                return height <= h[i] and l <= i and i <= r;
            };

            if (canreach(i, j)) {
                // we can go between this to other nodes
                FD(ni, i-1, -1) if (canreach(ni, j)) {
                    edges.emplace_back(abs(x[i] - x[ni]), pair(ni, j));
                    break;
                }
                F(ni, i+1, n) if (canreach(ni, j)) {
                    edges.emplace_back(abs(x[i] - x[ni]), pair(ni, j));
                    break;
                }
            }
        }   

        for (const auto &[w, to]: edges) {
            auto [nr, nc] = to;
            if (d + w < dist[nr][nc]) {
                dist[nr][nc] = d + w;
                pq.emplace(d + w, to);
            }
        }
    }

    return dist[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:23:37: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 | #define F(i, l, r) for (ll i = l; i < (r); ++i)
      |                                     ^
walk.cpp:44:5: note: in expansion of macro 'F'
   44 |     F(i, 0, y.size()) skywalks.emplace_back(l[i], r[i], y[i]);
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Runtime error 734 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4032 ms 5464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4032 ms 5464 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -