# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37074 | 2017-12-21T02:13:38 Z | leejseo | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 443 ms | 8628 KB |
#include <stdio.h> #include <algorithm> #include <vector> #include <queue> using namespace std; #define all(v) v.begin(), v.end() #define maxint 2E9 struct Node{ int u; int dist; Node (int u_, int d_) {u = u_; dist = d_;} bool operator < (const Node &a) const {return dist > a.dist;} }; int N, M; int B[30001]; int P[30001]; vector<int> V[30000]; int dist[30000]; void get_input(){ scanf("%d%d", &N, &M); for (int i=0; i<M; i++) { scanf("%d%d", &B[i], &P[i]); V[B[i]].push_back(P[i]); } for (int i=0; i<N; i++) { sort(all(V[i])); V[i].erase(unique(all(V[i])), V[i].end()); } } void dijkstra(){ for (int i=0; i<N; i++) { dist[i] = maxint; } int start = B[0]; dist[start] = 0; priority_queue<Node> Q; Q.push(Node(start, 0)); while (!Q.empty()){ int u = Q.top().u; int dist_u= Q.top().dist; Q.pop(); if (dist_u > dist[u]){ continue; } for (int i=0; i < (V[u]).size(); i++){ int power = V[u][i]; int to = u+power; int cost = dist_u + 1; while (to < N){ if (dist[to] > cost){ dist[to] = cost; Q.push(Node(to, cost)); if (binary_search(all(V[to]), power)) break; } to += power; cost += 1; } to = u-power; cost = dist_u + 1; while (to >= 0){ if (dist[to]>cost){ dist[to]=cost; Q.push(Node(to, cost)); if (binary_search(all(V[to]), power)) break; } to -= power; cost += 1; } } } } int main(){ get_input(); dijkstra(); int ans = dist[B[1]]; if (ans == maxint){ printf("-1\n"); } else{ printf("%d\n", ans); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
8 | Correct | 0 ms | 2224 KB | Output is correct |
9 | Correct | 0 ms | 2224 KB | Output is correct |
10 | Correct | 0 ms | 2224 KB | Output is correct |
11 | Correct | 0 ms | 2224 KB | Output is correct |
12 | Correct | 0 ms | 2224 KB | Output is correct |
13 | Correct | 0 ms | 2224 KB | Output is correct |
14 | Correct | 0 ms | 2224 KB | Output is correct |
15 | Correct | 0 ms | 2224 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
8 | Correct | 0 ms | 2224 KB | Output is correct |
9 | Correct | 0 ms | 2224 KB | Output is correct |
10 | Correct | 0 ms | 2224 KB | Output is correct |
11 | Correct | 0 ms | 2224 KB | Output is correct |
12 | Correct | 0 ms | 2224 KB | Output is correct |
13 | Correct | 0 ms | 2224 KB | Output is correct |
14 | Correct | 0 ms | 2224 KB | Output is correct |
15 | Correct | 0 ms | 2224 KB | Output is correct |
16 | Correct | 0 ms | 2224 KB | Output is correct |
17 | Correct | 0 ms | 2356 KB | Output is correct |
18 | Correct | 0 ms | 2224 KB | Output is correct |
19 | Correct | 0 ms | 2224 KB | Output is correct |
20 | Correct | 3 ms | 2356 KB | Output is correct |
21 | Correct | 0 ms | 2224 KB | Output is correct |
22 | Correct | 0 ms | 2224 KB | Output is correct |
23 | Correct | 0 ms | 2224 KB | Output is correct |
24 | Correct | 3 ms | 2368 KB | Output is correct |
25 | Correct | 0 ms | 2356 KB | Output is correct |
26 | Correct | 0 ms | 2224 KB | Output is correct |
27 | Correct | 0 ms | 2224 KB | Output is correct |
28 | Correct | 0 ms | 2356 KB | Output is correct |
29 | Correct | 0 ms | 2504 KB | Output is correct |
30 | Correct | 0 ms | 2368 KB | Output is correct |
31 | Correct | 0 ms | 2368 KB | Output is correct |
32 | Correct | 0 ms | 2372 KB | Output is correct |
33 | Correct | 3 ms | 2708 KB | Output is correct |
34 | Correct | 3 ms | 2708 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
8 | Correct | 0 ms | 2224 KB | Output is correct |
9 | Correct | 0 ms | 2224 KB | Output is correct |
10 | Correct | 0 ms | 2224 KB | Output is correct |
11 | Correct | 0 ms | 2224 KB | Output is correct |
12 | Correct | 0 ms | 2224 KB | Output is correct |
13 | Correct | 0 ms | 2224 KB | Output is correct |
14 | Correct | 0 ms | 2224 KB | Output is correct |
15 | Correct | 0 ms | 2224 KB | Output is correct |
16 | Correct | 0 ms | 2224 KB | Output is correct |
17 | Correct | 0 ms | 2356 KB | Output is correct |
18 | Correct | 0 ms | 2224 KB | Output is correct |
19 | Correct | 0 ms | 2224 KB | Output is correct |
20 | Correct | 0 ms | 2356 KB | Output is correct |
21 | Correct | 0 ms | 2224 KB | Output is correct |
22 | Correct | 0 ms | 2224 KB | Output is correct |
23 | Correct | 0 ms | 2224 KB | Output is correct |
24 | Correct | 0 ms | 2368 KB | Output is correct |
25 | Correct | 0 ms | 2356 KB | Output is correct |
26 | Correct | 0 ms | 2224 KB | Output is correct |
27 | Correct | 0 ms | 2224 KB | Output is correct |
28 | Correct | 0 ms | 2356 KB | Output is correct |
29 | Correct | 3 ms | 2504 KB | Output is correct |
30 | Correct | 0 ms | 2368 KB | Output is correct |
31 | Correct | 0 ms | 2368 KB | Output is correct |
32 | Correct | 0 ms | 2372 KB | Output is correct |
33 | Correct | 0 ms | 2708 KB | Output is correct |
34 | Correct | 3 ms | 2708 KB | Output is correct |
35 | Correct | 6 ms | 2488 KB | Output is correct |
36 | Correct | 3 ms | 2356 KB | Output is correct |
37 | Correct | 6 ms | 2488 KB | Output is correct |
38 | Correct | 9 ms | 2672 KB | Output is correct |
39 | Correct | 13 ms | 2668 KB | Output is correct |
40 | Correct | 9 ms | 2672 KB | Output is correct |
41 | Correct | 13 ms | 2672 KB | Output is correct |
42 | Correct | 6 ms | 2500 KB | Output is correct |
43 | Correct | 6 ms | 2500 KB | Output is correct |
44 | Correct | 13 ms | 2496 KB | Output is correct |
45 | Correct | 13 ms | 2868 KB | Output is correct |
46 | Correct | 19 ms | 2876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2224 KB | Output is correct |
2 | Correct | 0 ms | 2224 KB | Output is correct |
3 | Correct | 0 ms | 2224 KB | Output is correct |
4 | Correct | 0 ms | 2224 KB | Output is correct |
5 | Correct | 0 ms | 2224 KB | Output is correct |
6 | Correct | 0 ms | 2224 KB | Output is correct |
7 | Correct | 0 ms | 2224 KB | Output is correct |
8 | Correct | 0 ms | 2224 KB | Output is correct |
9 | Correct | 0 ms | 2224 KB | Output is correct |
10 | Correct | 0 ms | 2224 KB | Output is correct |
11 | Correct | 0 ms | 2224 KB | Output is correct |
12 | Correct | 0 ms | 2224 KB | Output is correct |
13 | Correct | 0 ms | 2224 KB | Output is correct |
14 | Correct | 0 ms | 2224 KB | Output is correct |
15 | Correct | 0 ms | 2224 KB | Output is correct |
16 | Correct | 0 ms | 2224 KB | Output is correct |
17 | Correct | 0 ms | 2356 KB | Output is correct |
18 | Correct | 0 ms | 2224 KB | Output is correct |
19 | Correct | 0 ms | 2224 KB | Output is correct |
20 | Correct | 3 ms | 2356 KB | Output is correct |
21 | Correct | 0 ms | 2224 KB | Output is correct |
22 | Correct | 0 ms | 2224 KB | Output is correct |
23 | Correct | 0 ms | 2224 KB | Output is correct |
24 | Correct | 0 ms | 2368 KB | Output is correct |
25 | Correct | 0 ms | 2356 KB | Output is correct |
26 | Correct | 0 ms | 2224 KB | Output is correct |
27 | Correct | 0 ms | 2224 KB | Output is correct |
28 | Correct | 0 ms | 2356 KB | Output is correct |
29 | Correct | 0 ms | 2504 KB | Output is correct |
30 | Correct | 0 ms | 2368 KB | Output is correct |
31 | Correct | 0 ms | 2368 KB | Output is correct |
32 | Correct | 0 ms | 2372 KB | Output is correct |
33 | Correct | 3 ms | 2708 KB | Output is correct |
34 | Correct | 3 ms | 2708 KB | Output is correct |
35 | Correct | 9 ms | 2488 KB | Output is correct |
36 | Correct | 3 ms | 2356 KB | Output is correct |
37 | Correct | 9 ms | 2488 KB | Output is correct |
38 | Correct | 13 ms | 2672 KB | Output is correct |
39 | Correct | 13 ms | 2668 KB | Output is correct |
40 | Correct | 13 ms | 2672 KB | Output is correct |
41 | Correct | 9 ms | 2672 KB | Output is correct |
42 | Correct | 6 ms | 2500 KB | Output is correct |
43 | Correct | 9 ms | 2500 KB | Output is correct |
44 | Correct | 6 ms | 2496 KB | Output is correct |
45 | Correct | 13 ms | 2868 KB | Output is correct |
46 | Correct | 9 ms | 2876 KB | Output is correct |
47 | Correct | 13 ms | 3420 KB | Output is correct |
48 | Correct | 9 ms | 2752 KB | Output is correct |
49 | Correct | 9 ms | 2752 KB | Output is correct |
50 | Correct | 9 ms | 2620 KB | Output is correct |
51 | Correct | 29 ms | 3668 KB | Output is correct |
52 | Correct | 26 ms | 3672 KB | Output is correct |
53 | Correct | 16 ms | 3672 KB | Output is correct |
54 | Correct | 0 ms | 2496 KB | Output is correct |
55 | Correct | 0 ms | 2496 KB | Output is correct |
56 | Correct | 443 ms | 3148 KB | Output is correct |
57 | Correct | 39 ms | 3912 KB | Output is correct |
58 | Correct | 9 ms | 2564 KB | Output is correct |
59 | Correct | 9 ms | 2564 KB | Output is correct |
60 | Correct | 9 ms | 2572 KB | Output is correct |
61 | Correct | 6 ms | 2580 KB | Output is correct |
62 | Correct | 13 ms | 3148 KB | Output is correct |
63 | Correct | 33 ms | 4080 KB | Output is correct |
64 | Correct | 23 ms | 4040 KB | Output is correct |
65 | Correct | 36 ms | 5600 KB | Output is correct |
66 | Correct | 113 ms | 8628 KB | Output is correct |
67 | Correct | 109 ms | 8628 KB | Output is correct |