Submission #1110702

# Submission time Handle Problem Language Result Execution time Memory
1110702 2024-11-10T08:29:57 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
272 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)

template <class X, class Y>
    bool minimize(X &x, Y y) {
        if (x > y) return x = y, true;
        else return false;
    }

int n, m;

const ll INF = (ll) 1e18 + 7;

#define ii pair <long long, int>

#define MAX 50'005
vector <ii> adj[MAX + 2];
int b[MAX + 2], p[MAX + 2];
ll dist[MAX + 2];
vector <int> jump[MAX + 2];

void Dijkstra(int s) {
    priority_queue <ii, vector <ii>, greater <ii>> q;
    FOR(i, 1, n) dist[i] = INF;
    dist[s] = 0;
    q.push({0, s});

    while (!q.empty()) {
        ll cost = q.top().first;
        int u = q.top().second;
        q.pop();
        if (cost > dist[u]) continue;

        for (auto it : adj[u]) {
            int v = it.first, w = it.second;
            if (minimize(dist[v], dist[u] + w)) {
                q.push({dist[v], v});
            }
        }
    }

    cout << (dist[b[2]] != INF ? dist[b[2]] : -1);
}

void add_edge(int u, int v, int w) {
    adj[u].push_back({v, w});
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    #define task "sky"
    if (fopen(task".inp","r")) {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n >> m;
    FOR(i, 1, m) {
        cin >> b[i] >> p[i];
        ++b[i];
        jump[b[i]].push_back(p[i]);
    }

    FOR(i, 1, n) {
        for (int x : jump[i]) {
            int j = x + i, cur = 1;
            while (j <= n) {
                add_edge(i, j, cur);
                j += x;
                ++cur;
            }
            j = i - x, cur = 1;
            while (j >= 1) {
                add_edge(i, j, cur);
                j -= x;
                ++cur;
            }
        }
    }

    Dijkstra(b[1]);

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3576 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3388 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3408 KB Output is correct
8 Correct 2 ms 3408 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 2 ms 3408 KB Output is correct
11 Correct 2 ms 3664 KB Output is correct
12 Correct 6 ms 9824 KB Output is correct
13 Correct 6 ms 9860 KB Output is correct
14 Correct 2 ms 3664 KB Output is correct
15 Correct 2 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 1 ms 3408 KB Output is correct
3 Correct 2 ms 3408 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3408 KB Output is correct
8 Correct 2 ms 3408 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 2 ms 3408 KB Output is correct
11 Correct 2 ms 3664 KB Output is correct
12 Correct 6 ms 9840 KB Output is correct
13 Correct 6 ms 9920 KB Output is correct
14 Correct 2 ms 3664 KB Output is correct
15 Correct 2 ms 3664 KB Output is correct
16 Correct 2 ms 3664 KB Output is correct
17 Correct 3 ms 3920 KB Output is correct
18 Correct 2 ms 3664 KB Output is correct
19 Correct 2 ms 3664 KB Output is correct
20 Correct 90 ms 67768 KB Output is correct
21 Correct 2 ms 3408 KB Output is correct
22 Correct 2 ms 3664 KB Output is correct
23 Correct 2 ms 3664 KB Output is correct
24 Correct 3 ms 3920 KB Output is correct
25 Correct 3 ms 3744 KB Output is correct
26 Correct 70 ms 69292 KB Output is correct
27 Correct 64 ms 69308 KB Output is correct
28 Correct 2 ms 3920 KB Output is correct
29 Correct 5 ms 4944 KB Output is correct
30 Correct 3 ms 3920 KB Output is correct
31 Correct 3 ms 4432 KB Output is correct
32 Correct 3 ms 4176 KB Output is correct
33 Correct 6 ms 6100 KB Output is correct
34 Correct 6 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3576 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3408 KB Output is correct
8 Correct 2 ms 3408 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 2 ms 3408 KB Output is correct
11 Correct 2 ms 3832 KB Output is correct
12 Correct 5 ms 9672 KB Output is correct
13 Correct 6 ms 10088 KB Output is correct
14 Correct 2 ms 3664 KB Output is correct
15 Correct 2 ms 3664 KB Output is correct
16 Correct 2 ms 3664 KB Output is correct
17 Correct 3 ms 3920 KB Output is correct
18 Correct 2 ms 3664 KB Output is correct
19 Correct 3 ms 3720 KB Output is correct
20 Correct 92 ms 67768 KB Output is correct
21 Correct 2 ms 3408 KB Output is correct
22 Correct 2 ms 3664 KB Output is correct
23 Correct 3 ms 3664 KB Output is correct
24 Correct 3 ms 3920 KB Output is correct
25 Correct 3 ms 3740 KB Output is correct
26 Correct 67 ms 71552 KB Output is correct
27 Correct 66 ms 69284 KB Output is correct
28 Correct 3 ms 3920 KB Output is correct
29 Correct 4 ms 4944 KB Output is correct
30 Correct 3 ms 3920 KB Output is correct
31 Correct 3 ms 4432 KB Output is correct
32 Correct 3 ms 4176 KB Output is correct
33 Correct 6 ms 6100 KB Output is correct
34 Correct 6 ms 6100 KB Output is correct
35 Correct 9 ms 6736 KB Output is correct
36 Correct 4 ms 3920 KB Output is correct
37 Correct 11 ms 9808 KB Output is correct
38 Correct 12 ms 8528 KB Output is correct
39 Correct 12 ms 8952 KB Output is correct
40 Correct 12 ms 8784 KB Output is correct
41 Correct 11 ms 8528 KB Output is correct
42 Runtime error 272 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3408 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3580 KB Output is correct
7 Correct 2 ms 3408 KB Output is correct
8 Correct 2 ms 3576 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 2 ms 3408 KB Output is correct
11 Correct 3 ms 3832 KB Output is correct
12 Correct 6 ms 9672 KB Output is correct
13 Correct 6 ms 9920 KB Output is correct
14 Correct 2 ms 3664 KB Output is correct
15 Correct 2 ms 3664 KB Output is correct
16 Correct 2 ms 3664 KB Output is correct
17 Correct 3 ms 3920 KB Output is correct
18 Correct 2 ms 3664 KB Output is correct
19 Correct 2 ms 3664 KB Output is correct
20 Correct 90 ms 67664 KB Output is correct
21 Correct 2 ms 3408 KB Output is correct
22 Correct 2 ms 3664 KB Output is correct
23 Correct 3 ms 3664 KB Output is correct
24 Correct 3 ms 3920 KB Output is correct
25 Correct 2 ms 3664 KB Output is correct
26 Correct 62 ms 71360 KB Output is correct
27 Correct 62 ms 71348 KB Output is correct
28 Correct 3 ms 4088 KB Output is correct
29 Correct 4 ms 4944 KB Output is correct
30 Correct 3 ms 3920 KB Output is correct
31 Correct 4 ms 4432 KB Output is correct
32 Correct 3 ms 4176 KB Output is correct
33 Correct 8 ms 6100 KB Output is correct
34 Correct 6 ms 6100 KB Output is correct
35 Correct 9 ms 6544 KB Output is correct
36 Correct 3 ms 3920 KB Output is correct
37 Correct 12 ms 9808 KB Output is correct
38 Correct 13 ms 8624 KB Output is correct
39 Correct 13 ms 8948 KB Output is correct
40 Correct 13 ms 8784 KB Output is correct
41 Correct 10 ms 8528 KB Output is correct
42 Runtime error 256 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -