#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxN = 3e4, OO = 0x3f3f3f3f;
int N, M;
vector<int> doges[mxN];
int dijkstra(int st, int en) {
vector<int> dist(N, OO);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push({0, st});
while(pq.size()) {
auto node = pq.top();
pq.pop();
if (node.first > dist[node.second])
continue;
dist[node.second] = node.first;
if (node.second == en)
return node.first;
for (auto doge : doges[node.second]) {
for (int i = node.second+doge, j = 1; i < N; i+=doge, j++) {
if (dist[i] > node.first + j) {
dist[i] = node.first + j;
pq.push({dist[i], i});
}
}
for (int i = node.second-doge, j = 1; i >= 0; i-=doge, j++) {
if (dist[i] > node.first + j) {
dist[i] = node.first + j;
pq.push({dist[i], i});
}
}
}
}
return -1;
}
void solve() {
cin >> N >> M;
int stB, enB;
for (int i = 0; i < M; i++) {
int B, P;
cin >> B >> P;
if (!i) stB = B;
if (!(i-1)) enB = B;
doges[B].push_back(P);
}
cout << dijkstra(stB, enB);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
Compilation message
skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:58:27: warning: 'enB' may be used uninitialized in this function [-Wmaybe-uninitialized]
58 | cout << dijkstra(stB, enB);
| ^
skyscraper.cpp:58:27: warning: 'stB' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
1016 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
1024 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Correct |
1 ms |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
972 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
2 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Correct |
1 ms |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
972 KB |
Output is correct |
14 |
Correct |
2 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
972 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
7 ms |
1032 KB |
Output is correct |
21 |
Correct |
1 ms |
1032 KB |
Output is correct |
22 |
Correct |
1 ms |
972 KB |
Output is correct |
23 |
Correct |
1 ms |
972 KB |
Output is correct |
24 |
Correct |
2 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1028 KB |
Output is correct |
27 |
Correct |
2 ms |
1024 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
29 |
Correct |
3 ms |
1228 KB |
Output is correct |
30 |
Correct |
2 ms |
1100 KB |
Output is correct |
31 |
Correct |
2 ms |
1152 KB |
Output is correct |
32 |
Correct |
2 ms |
1100 KB |
Output is correct |
33 |
Correct |
3 ms |
1228 KB |
Output is correct |
34 |
Correct |
3 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
1016 KB |
Output is correct |
3 |
Correct |
2 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
1024 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Correct |
1 ms |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
972 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
2 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
7 ms |
1208 KB |
Output is correct |
21 |
Correct |
1 ms |
984 KB |
Output is correct |
22 |
Correct |
1 ms |
972 KB |
Output is correct |
23 |
Correct |
1 ms |
972 KB |
Output is correct |
24 |
Correct |
2 ms |
1100 KB |
Output is correct |
25 |
Correct |
2 ms |
1032 KB |
Output is correct |
26 |
Correct |
1 ms |
1036 KB |
Output is correct |
27 |
Correct |
2 ms |
972 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
29 |
Correct |
3 ms |
1228 KB |
Output is correct |
30 |
Correct |
2 ms |
1100 KB |
Output is correct |
31 |
Correct |
2 ms |
1100 KB |
Output is correct |
32 |
Correct |
2 ms |
1100 KB |
Output is correct |
33 |
Correct |
4 ms |
1228 KB |
Output is correct |
34 |
Correct |
3 ms |
1280 KB |
Output is correct |
35 |
Correct |
11 ms |
1536 KB |
Output is correct |
36 |
Correct |
4 ms |
1100 KB |
Output is correct |
37 |
Correct |
9 ms |
1356 KB |
Output is correct |
38 |
Correct |
8 ms |
1548 KB |
Output is correct |
39 |
Correct |
11 ms |
1484 KB |
Output is correct |
40 |
Correct |
8 ms |
1516 KB |
Output is correct |
41 |
Correct |
8 ms |
1540 KB |
Output is correct |
42 |
Correct |
8 ms |
1484 KB |
Output is correct |
43 |
Correct |
6 ms |
1440 KB |
Output is correct |
44 |
Correct |
38 ms |
1412 KB |
Output is correct |
45 |
Correct |
9 ms |
1580 KB |
Output is correct |
46 |
Correct |
10 ms |
1584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
972 KB |
Output is correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
2 ms |
1024 KB |
Output is correct |
12 |
Correct |
1 ms |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
972 KB |
Output is correct |
14 |
Correct |
2 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
1032 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
2 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
972 KB |
Output is correct |
20 |
Correct |
6 ms |
1136 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
972 KB |
Output is correct |
23 |
Correct |
2 ms |
972 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
2 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1036 KB |
Output is correct |
27 |
Correct |
2 ms |
1032 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
29 |
Correct |
2 ms |
1228 KB |
Output is correct |
30 |
Correct |
2 ms |
1020 KB |
Output is correct |
31 |
Correct |
2 ms |
1100 KB |
Output is correct |
32 |
Correct |
2 ms |
1100 KB |
Output is correct |
33 |
Correct |
4 ms |
1228 KB |
Output is correct |
34 |
Correct |
3 ms |
1228 KB |
Output is correct |
35 |
Correct |
7 ms |
1540 KB |
Output is correct |
36 |
Correct |
3 ms |
1100 KB |
Output is correct |
37 |
Correct |
9 ms |
1436 KB |
Output is correct |
38 |
Correct |
11 ms |
1548 KB |
Output is correct |
39 |
Correct |
8 ms |
1484 KB |
Output is correct |
40 |
Correct |
9 ms |
1484 KB |
Output is correct |
41 |
Correct |
9 ms |
1512 KB |
Output is correct |
42 |
Correct |
7 ms |
1484 KB |
Output is correct |
43 |
Correct |
7 ms |
1484 KB |
Output is correct |
44 |
Correct |
56 ms |
1528 KB |
Output is correct |
45 |
Correct |
9 ms |
1612 KB |
Output is correct |
46 |
Correct |
8 ms |
1612 KB |
Output is correct |
47 |
Correct |
11 ms |
2248 KB |
Output is correct |
48 |
Correct |
10 ms |
1696 KB |
Output is correct |
49 |
Correct |
7 ms |
1740 KB |
Output is correct |
50 |
Correct |
5 ms |
1612 KB |
Output is correct |
51 |
Correct |
17 ms |
3200 KB |
Output is correct |
52 |
Correct |
17 ms |
2668 KB |
Output is correct |
53 |
Correct |
10 ms |
2260 KB |
Output is correct |
54 |
Correct |
2 ms |
1356 KB |
Output is correct |
55 |
Correct |
3 ms |
1356 KB |
Output is correct |
56 |
Correct |
825 ms |
2636 KB |
Output is correct |
57 |
Correct |
4 ms |
1864 KB |
Output is correct |
58 |
Correct |
997 ms |
1612 KB |
Output is correct |
59 |
Correct |
12 ms |
1740 KB |
Output is correct |
60 |
Correct |
8 ms |
1612 KB |
Output is correct |
61 |
Correct |
9 ms |
1740 KB |
Output is correct |
62 |
Correct |
15 ms |
2332 KB |
Output is correct |
63 |
Correct |
32 ms |
2688 KB |
Output is correct |
64 |
Correct |
33 ms |
3776 KB |
Output is correct |
65 |
Correct |
39 ms |
3776 KB |
Output is correct |
66 |
Correct |
58 ms |
3648 KB |
Output is correct |
67 |
Correct |
43 ms |
3648 KB |
Output is correct |