Submission #482761

# Submission time Handle Problem Language Result Execution time Memory
482761 2021-10-26T09:47:45 Z jalsol Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
173 ms 68036 KB
#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#endif

using namespace std;

const bool __initialization = []() {
    cin.tie(nullptr)->sync_with_stdio(false);
#define TASK "empty"
    if (fopen(TASK".inp", "r")) {
        (void)(!freopen(TASK".inp", "r", stdin));
        (void)(!freopen(TASK".out", "w", stdout)); }
    cout << setprecision(12) << fixed;
    return true;
}();

using ll = long long;
using ld = long double;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)

template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }

constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;

// =============================================================================

constexpr int maxn = 3e4 + 5;

struct Link {
    int v, c;
};

struct State {
    int u, du;

    bool operator<(const State& o) const {
        return du > o.du;
    }
};

int len, n;
int a[maxn], pw[maxn];

set<int> building[maxn];
vector<Link> g[maxn];

int d[maxn];
priority_queue<State> q;

void Dijkstra() {
    memset(d, 0x3e, sizeof(int) * len);
    d[a[0]] = 0;
    q.push({a[0], d[a[0]]});

    while (isz(q)) {
        auto [u, du] = q.top(); q.pop();
        if (du != d[u]) continue;

        Fe (&[v, c] : g[u]) {
            if (chmin(d[v], d[u] + c)) {
                q.push({v, d[v]});
            }
        }
    }
}

signed main() {
    cin >> len >> n;
    Rep (i, n) cin >> a[i] >> pw[i];

    Rep (i, n) {
        building[a[i]].insert(pw[i]);
    }

    Rep (i, len) {
        Fe (p : building[i]) {
            for (int other = i + p; other < len; other += p) {
                g[i].push_back({other, (other - i) / p});
                if (building[other].count(p)) break;
            }
            for (int other = i - p; other >= 0; other -= p) {
                g[i].push_back({other, (i - other) / p});
                if (building[other].count(p)) break;
            }
        }
    }

    Dijkstra();
    int ans = d[a[1]];
    if (ans >= inf) ans = -1;
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2380 KB Output is correct
2 Correct 2 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 1 ms 2380 KB Output is correct
5 Correct 1 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 1 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2380 KB Output is correct
2 Correct 1 ms 2380 KB Output is correct
3 Correct 1 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 1 ms 2380 KB Output is correct
6 Correct 1 ms 2380 KB Output is correct
7 Correct 1 ms 2380 KB Output is correct
8 Correct 2 ms 2380 KB Output is correct
9 Correct 1 ms 2380 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 2508 KB Output is correct
12 Correct 1 ms 2380 KB Output is correct
13 Correct 1 ms 2380 KB Output is correct
14 Correct 2 ms 2508 KB Output is correct
15 Correct 2 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2380 KB Output is correct
2 Correct 1 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 1 ms 2380 KB Output is correct
8 Correct 1 ms 2380 KB Output is correct
9 Correct 1 ms 2380 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 2508 KB Output is correct
12 Correct 1 ms 2380 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 2 ms 2508 KB Output is correct
15 Correct 2 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2592 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 2 ms 2508 KB Output is correct
21 Correct 2 ms 2508 KB Output is correct
22 Correct 2 ms 2508 KB Output is correct
23 Correct 2 ms 2508 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 3 ms 2508 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 2 ms 2764 KB Output is correct
29 Correct 3 ms 3276 KB Output is correct
30 Correct 2 ms 2764 KB Output is correct
31 Correct 2 ms 2892 KB Output is correct
32 Correct 2 ms 2764 KB Output is correct
33 Correct 5 ms 4044 KB Output is correct
34 Correct 5 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2380 KB Output is correct
2 Correct 1 ms 2380 KB Output is correct
3 Correct 2 ms 2328 KB Output is correct
4 Correct 1 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 1 ms 2380 KB Output is correct
7 Correct 1 ms 2380 KB Output is correct
8 Correct 1 ms 2380 KB Output is correct
9 Correct 1 ms 2380 KB Output is correct
10 Correct 1 ms 2380 KB Output is correct
11 Correct 2 ms 2508 KB Output is correct
12 Correct 1 ms 2380 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 3 ms 2508 KB Output is correct
15 Correct 2 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 3 ms 2700 KB Output is correct
18 Correct 2 ms 2508 KB Output is correct
19 Correct 2 ms 2508 KB Output is correct
20 Correct 2 ms 2508 KB Output is correct
21 Correct 1 ms 2508 KB Output is correct
22 Correct 2 ms 2508 KB Output is correct
23 Correct 2 ms 2508 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2508 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 3 ms 2764 KB Output is correct
29 Correct 4 ms 3276 KB Output is correct
30 Correct 2 ms 2764 KB Output is correct
31 Correct 3 ms 2908 KB Output is correct
32 Correct 2 ms 2764 KB Output is correct
33 Correct 5 ms 3944 KB Output is correct
34 Correct 6 ms 4044 KB Output is correct
35 Correct 14 ms 4892 KB Output is correct
36 Correct 3 ms 2892 KB Output is correct
37 Correct 16 ms 5528 KB Output is correct
38 Correct 17 ms 5836 KB Output is correct
39 Correct 20 ms 5852 KB Output is correct
40 Correct 18 ms 5760 KB Output is correct
41 Correct 17 ms 5760 KB Output is correct
42 Correct 8 ms 2764 KB Output is correct
43 Correct 7 ms 2764 KB Output is correct
44 Correct 5 ms 2764 KB Output is correct
45 Correct 18 ms 8540 KB Output is correct
46 Correct 18 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2380 KB Output is correct
2 Correct 1 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 1 ms 2380 KB Output is correct
5 Correct 1 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 1 ms 2444 KB Output is correct
8 Correct 2 ms 2380 KB Output is correct
9 Correct 2 ms 2508 KB Output is correct
10 Correct 1 ms 2380 KB Output is correct
11 Correct 2 ms 2508 KB Output is correct
12 Correct 1 ms 2380 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 2 ms 2508 KB Output is correct
15 Correct 2 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2508 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 1 ms 2508 KB Output is correct
22 Correct 1 ms 2508 KB Output is correct
23 Correct 2 ms 2508 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2508 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 2 ms 2764 KB Output is correct
29 Correct 3 ms 3276 KB Output is correct
30 Correct 2 ms 2764 KB Output is correct
31 Correct 3 ms 2892 KB Output is correct
32 Correct 2 ms 2764 KB Output is correct
33 Correct 5 ms 4044 KB Output is correct
34 Correct 5 ms 4060 KB Output is correct
35 Correct 13 ms 4784 KB Output is correct
36 Correct 3 ms 2892 KB Output is correct
37 Correct 15 ms 5580 KB Output is correct
38 Correct 18 ms 5804 KB Output is correct
39 Correct 18 ms 5880 KB Output is correct
40 Correct 19 ms 5812 KB Output is correct
41 Correct 17 ms 5796 KB Output is correct
42 Correct 5 ms 2764 KB Output is correct
43 Correct 5 ms 2764 KB Output is correct
44 Correct 6 ms 2764 KB Output is correct
45 Correct 19 ms 8652 KB Output is correct
46 Correct 18 ms 8540 KB Output is correct
47 Correct 37 ms 12864 KB Output is correct
48 Correct 13 ms 6088 KB Output is correct
49 Correct 12 ms 5196 KB Output is correct
50 Correct 8 ms 4856 KB Output is correct
51 Correct 33 ms 8136 KB Output is correct
52 Correct 29 ms 8556 KB Output is correct
53 Correct 14 ms 5704 KB Output is correct
54 Correct 3 ms 3020 KB Output is correct
55 Correct 4 ms 3400 KB Output is correct
56 Correct 10 ms 5128 KB Output is correct
57 Correct 28 ms 11600 KB Output is correct
58 Correct 7 ms 3792 KB Output is correct
59 Correct 9 ms 4040 KB Output is correct
60 Correct 9 ms 4808 KB Output is correct
61 Correct 10 ms 4148 KB Output is correct
62 Correct 18 ms 9288 KB Output is correct
63 Correct 58 ms 25540 KB Output is correct
64 Correct 61 ms 28900 KB Output is correct
65 Correct 90 ms 39476 KB Output is correct
66 Correct 173 ms 67916 KB Output is correct
67 Correct 168 ms 68036 KB Output is correct