Submission #248558

# Submission time Handle Problem Language Result Execution time Memory
248558 2020-07-12T18:05:22 Z dolphingarlic Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
203 ms 65536 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

set<int> doges[30000];
vector<pair<int, int>> graph[30000];
int visited[30000];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, src, dest;
    cin >> n >> m;
    FOR(i, 0, m) {
        int b, p;
        cin >> b >> p;
        if (!i) src = b;
        if (i == 1) dest = b;
        doges[b].insert(p);
    }

    FOR(i, 0, n) {
        for (int j : doges[i]) {
            for (int k = i + j, cnt = 1; k < n; k += j, cnt++) {
                graph[i].push_back({k, cnt});
                if (doges[k].find(j) != doges[k].end()) break;
            }
            for (int k = i - j, cnt = 1; k >= 0; k -= j, cnt++) {
                graph[i].push_back({k, cnt});
                if (doges[k].find(j) != doges[k].end()) break;
            }
        }
    }

    memset(visited, 0x3f, sizeof visited);
    priority_queue<pair<int, int>> pq;
    pq.push({0, src});
    visited[src] = 0;
    while (pq.size()) {
        int dist, node;
        tie(dist, node) = pq.top();
        pq.pop();
        if (node == dest) return cout << -dist, 0;
        for (pair<int, int> i : graph[node]) {
            if (i.second - dist < visited[i.first]) {
                visited[i.first] = i.second - dist;
                pq.push({dist - i.second, i.first});
            }
        }
    }
    cout << -1;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:18: warning: 'src' may be used uninitialized in this function [-Wmaybe-uninitialized]
     visited[src] = 0;
     ~~~~~~~~~~~~~^~~
skyscraper.cpp:44:9: warning: 'dest' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (node == dest) return cout << -dist, 0;
         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2560 KB Output is correct
2 Correct 1 ms 2560 KB Output is correct
3 Correct 2 ms 2560 KB Output is correct
4 Correct 1 ms 2560 KB Output is correct
5 Correct 1 ms 2560 KB Output is correct
6 Correct 1 ms 2560 KB Output is correct
7 Correct 1 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2560 KB Output is correct
2 Correct 1 ms 2560 KB Output is correct
3 Correct 1 ms 2560 KB Output is correct
4 Correct 2 ms 2560 KB Output is correct
5 Correct 1 ms 2560 KB Output is correct
6 Correct 1 ms 2560 KB Output is correct
7 Correct 1 ms 2560 KB Output is correct
8 Correct 2 ms 2560 KB Output is correct
9 Correct 1 ms 2560 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2560 KB Output is correct
2 Correct 1 ms 2560 KB Output is correct
3 Correct 1 ms 2560 KB Output is correct
4 Correct 1 ms 2560 KB Output is correct
5 Correct 1 ms 2560 KB Output is correct
6 Correct 1 ms 2560 KB Output is correct
7 Correct 1 ms 2560 KB Output is correct
8 Correct 1 ms 2560 KB Output is correct
9 Correct 1 ms 2560 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 3 ms 2688 KB Output is correct
17 Correct 4 ms 2816 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 3 ms 2816 KB Output is correct
25 Correct 2 ms 2816 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2944 KB Output is correct
29 Correct 4 ms 3328 KB Output is correct
30 Correct 2 ms 2816 KB Output is correct
31 Correct 3 ms 3072 KB Output is correct
32 Correct 4 ms 2944 KB Output is correct
33 Correct 6 ms 3964 KB Output is correct
34 Correct 5 ms 3964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2560 KB Output is correct
2 Correct 1 ms 2560 KB Output is correct
3 Correct 1 ms 2560 KB Output is correct
4 Correct 1 ms 2560 KB Output is correct
5 Correct 1 ms 2560 KB Output is correct
6 Correct 1 ms 2560 KB Output is correct
7 Correct 1 ms 2560 KB Output is correct
8 Correct 2 ms 2560 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 3 ms 2816 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2792 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 3 ms 2816 KB Output is correct
25 Correct 3 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2944 KB Output is correct
29 Correct 4 ms 3328 KB Output is correct
30 Correct 3 ms 2816 KB Output is correct
31 Correct 3 ms 3072 KB Output is correct
32 Correct 3 ms 2944 KB Output is correct
33 Correct 6 ms 3964 KB Output is correct
34 Correct 5 ms 3964 KB Output is correct
35 Correct 18 ms 4864 KB Output is correct
36 Correct 4 ms 2944 KB Output is correct
37 Correct 19 ms 5504 KB Output is correct
38 Correct 28 ms 5752 KB Output is correct
39 Correct 22 ms 5752 KB Output is correct
40 Correct 23 ms 5760 KB Output is correct
41 Correct 23 ms 5752 KB Output is correct
42 Correct 7 ms 2688 KB Output is correct
43 Correct 7 ms 2688 KB Output is correct
44 Correct 7 ms 2688 KB Output is correct
45 Correct 27 ms 8320 KB Output is correct
46 Correct 23 ms 8316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2560 KB Output is correct
2 Correct 1 ms 2560 KB Output is correct
3 Correct 1 ms 2560 KB Output is correct
4 Correct 1 ms 2560 KB Output is correct
5 Correct 1 ms 2560 KB Output is correct
6 Correct 2 ms 2560 KB Output is correct
7 Correct 1 ms 2560 KB Output is correct
8 Correct 1 ms 2560 KB Output is correct
9 Correct 2 ms 2560 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 2 ms 2560 KB Output is correct
13 Correct 2 ms 2560 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 3 ms 2816 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 3 ms 2816 KB Output is correct
25 Correct 2 ms 2816 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 3 ms 2944 KB Output is correct
29 Correct 4 ms 3328 KB Output is correct
30 Correct 3 ms 2816 KB Output is correct
31 Correct 3 ms 3072 KB Output is correct
32 Correct 3 ms 2944 KB Output is correct
33 Correct 6 ms 3964 KB Output is correct
34 Correct 5 ms 3964 KB Output is correct
35 Correct 18 ms 4736 KB Output is correct
36 Correct 4 ms 2944 KB Output is correct
37 Correct 19 ms 5504 KB Output is correct
38 Correct 23 ms 5760 KB Output is correct
39 Correct 23 ms 5760 KB Output is correct
40 Correct 22 ms 5752 KB Output is correct
41 Correct 24 ms 5792 KB Output is correct
42 Correct 7 ms 2688 KB Output is correct
43 Correct 7 ms 2688 KB Output is correct
44 Correct 7 ms 2688 KB Output is correct
45 Correct 26 ms 8320 KB Output is correct
46 Correct 26 ms 8388 KB Output is correct
47 Correct 42 ms 12664 KB Output is correct
48 Correct 18 ms 6012 KB Output is correct
49 Correct 15 ms 4992 KB Output is correct
50 Correct 12 ms 4736 KB Output is correct
51 Correct 31 ms 7948 KB Output is correct
52 Correct 39 ms 8312 KB Output is correct
53 Correct 15 ms 4988 KB Output is correct
54 Correct 3 ms 3072 KB Output is correct
55 Correct 5 ms 3452 KB Output is correct
56 Correct 16 ms 4864 KB Output is correct
57 Correct 17 ms 11392 KB Output is correct
58 Correct 10 ms 3576 KB Output is correct
59 Correct 14 ms 3964 KB Output is correct
60 Correct 13 ms 4604 KB Output is correct
61 Correct 13 ms 3968 KB Output is correct
62 Correct 25 ms 9076 KB Output is correct
63 Correct 70 ms 25464 KB Output is correct
64 Correct 75 ms 28656 KB Output is correct
65 Correct 109 ms 38508 KB Output is correct
66 Correct 203 ms 65536 KB Output is correct
67 Correct 178 ms 65504 KB Output is correct