#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxN = 3e4+10, OO = INT_MAX;
int N, M;
set<int> doges[mxN];
vector<pair<int, int>> adj[mxN];
int dijkstra(int st, int en) {
vector<int> dist(mxN, OO);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push({0, st});
dist[st] = 0;
while(pq.size()) {
auto node = pq.top();
pq.pop();
if (node.first > dist[node.second])
continue;
for (auto it : adj[node.second]) {
if (dist[it.second] > node.first + it.first) {
dist[it.second] = node.first + it.first;
pq.push({dist[it.second], it.second});
}
}
}
if (dist[en] == OO)
dist[en] = -1;
return dist[en];
}
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].insert(P);
}
for (int i = 0; i < N; i++) {
for (auto doge : doges[i]) {
for (int to = i + doge, j = 1; to < N; to += doge, j++){
adj[i].push_back({j, to});
if (doges[to].count(doge)) break;
}
for (int to = i - doge, j = 1; to >= 0; to -= doge, j++){
adj[i].push_back({j, to});
if (doges[to].count(doge)) break;
}
}
}
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:60:27: warning: 'enB' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | cout << dijkstra(stB, enB);
| ^
skyscraper.cpp:60:27: warning: 'stB' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2508 KB |
Output is correct |
2 |
Correct |
2 ms |
2508 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
2 ms |
2508 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
2 ms |
2508 KB |
Output is correct |
7 |
Correct |
2 ms |
2508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2508 KB |
Output is correct |
2 |
Correct |
2 ms |
2560 KB |
Output is correct |
3 |
Correct |
2 ms |
2548 KB |
Output is correct |
4 |
Correct |
2 ms |
2508 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
2 ms |
2516 KB |
Output is correct |
7 |
Correct |
2 ms |
2508 KB |
Output is correct |
8 |
Correct |
2 ms |
2508 KB |
Output is correct |
9 |
Correct |
2 ms |
2508 KB |
Output is correct |
10 |
Correct |
2 ms |
2508 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2508 KB |
Output is correct |
13 |
Correct |
2 ms |
2508 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2508 KB |
Output is correct |
2 |
Correct |
2 ms |
2508 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
2 ms |
2540 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
2 ms |
2508 KB |
Output is correct |
7 |
Correct |
2 ms |
2508 KB |
Output is correct |
8 |
Correct |
2 ms |
2508 KB |
Output is correct |
9 |
Correct |
2 ms |
2508 KB |
Output is correct |
10 |
Correct |
2 ms |
2508 KB |
Output is correct |
11 |
Correct |
4 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2572 KB |
Output is correct |
13 |
Correct |
2 ms |
2508 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
4 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2508 KB |
Output is correct |
17 |
Correct |
4 ms |
2764 KB |
Output is correct |
18 |
Correct |
3 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2508 KB |
Output is correct |
20 |
Correct |
3 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2508 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
3 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
4 ms |
2764 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
2 ms |
2636 KB |
Output is correct |
28 |
Correct |
3 ms |
2764 KB |
Output is correct |
29 |
Correct |
5 ms |
3396 KB |
Output is correct |
30 |
Correct |
3 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
3020 KB |
Output is correct |
32 |
Correct |
4 ms |
2784 KB |
Output is correct |
33 |
Correct |
9 ms |
4044 KB |
Output is correct |
34 |
Correct |
10 ms |
4044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2508 KB |
Output is correct |
2 |
Correct |
3 ms |
2560 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
2 ms |
2508 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
2 ms |
2508 KB |
Output is correct |
7 |
Correct |
2 ms |
2508 KB |
Output is correct |
8 |
Correct |
2 ms |
2552 KB |
Output is correct |
9 |
Correct |
3 ms |
2560 KB |
Output is correct |
10 |
Correct |
3 ms |
2508 KB |
Output is correct |
11 |
Correct |
4 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2508 KB |
Output is correct |
13 |
Correct |
6 ms |
2508 KB |
Output is correct |
14 |
Correct |
4 ms |
2636 KB |
Output is correct |
15 |
Correct |
4 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2508 KB |
Output is correct |
17 |
Correct |
3 ms |
2764 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
3 ms |
2604 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2508 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
3 ms |
2636 KB |
Output is correct |
24 |
Correct |
4 ms |
2888 KB |
Output is correct |
25 |
Correct |
4 ms |
2764 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
3 ms |
2764 KB |
Output is correct |
29 |
Correct |
6 ms |
3404 KB |
Output is correct |
30 |
Correct |
3 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
3020 KB |
Output is correct |
32 |
Correct |
3 ms |
2892 KB |
Output is correct |
33 |
Correct |
8 ms |
4044 KB |
Output is correct |
34 |
Correct |
7 ms |
4044 KB |
Output is correct |
35 |
Correct |
22 ms |
4684 KB |
Output is correct |
36 |
Correct |
4 ms |
2892 KB |
Output is correct |
37 |
Correct |
19 ms |
5492 KB |
Output is correct |
38 |
Correct |
27 ms |
5728 KB |
Output is correct |
39 |
Correct |
24 ms |
5708 KB |
Output is correct |
40 |
Correct |
27 ms |
5688 KB |
Output is correct |
41 |
Correct |
29 ms |
5616 KB |
Output is correct |
42 |
Correct |
8 ms |
2764 KB |
Output is correct |
43 |
Correct |
8 ms |
2824 KB |
Output is correct |
44 |
Correct |
8 ms |
2892 KB |
Output is correct |
45 |
Correct |
27 ms |
8636 KB |
Output is correct |
46 |
Correct |
32 ms |
8680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2508 KB |
Output is correct |
2 |
Correct |
2 ms |
2508 KB |
Output is correct |
3 |
Correct |
2 ms |
2508 KB |
Output is correct |
4 |
Correct |
2 ms |
2508 KB |
Output is correct |
5 |
Correct |
2 ms |
2508 KB |
Output is correct |
6 |
Correct |
2 ms |
2508 KB |
Output is correct |
7 |
Correct |
2 ms |
2508 KB |
Output is correct |
8 |
Correct |
2 ms |
2508 KB |
Output is correct |
9 |
Correct |
2 ms |
2508 KB |
Output is correct |
10 |
Correct |
2 ms |
2508 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2508 KB |
Output is correct |
13 |
Correct |
2 ms |
2488 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2508 KB |
Output is correct |
17 |
Correct |
4 ms |
2764 KB |
Output is correct |
18 |
Correct |
3 ms |
2636 KB |
Output is correct |
19 |
Correct |
3 ms |
2508 KB |
Output is correct |
20 |
Correct |
3 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2508 KB |
Output is correct |
22 |
Correct |
2 ms |
2632 KB |
Output is correct |
23 |
Correct |
3 ms |
2636 KB |
Output is correct |
24 |
Correct |
4 ms |
2764 KB |
Output is correct |
25 |
Correct |
3 ms |
2764 KB |
Output is correct |
26 |
Correct |
2 ms |
2636 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
3 ms |
2764 KB |
Output is correct |
29 |
Correct |
5 ms |
3404 KB |
Output is correct |
30 |
Correct |
3 ms |
2764 KB |
Output is correct |
31 |
Correct |
4 ms |
3020 KB |
Output is correct |
32 |
Correct |
3 ms |
2892 KB |
Output is correct |
33 |
Correct |
8 ms |
4044 KB |
Output is correct |
34 |
Correct |
9 ms |
4044 KB |
Output is correct |
35 |
Correct |
24 ms |
4640 KB |
Output is correct |
36 |
Correct |
4 ms |
2892 KB |
Output is correct |
37 |
Correct |
19 ms |
5520 KB |
Output is correct |
38 |
Correct |
23 ms |
5708 KB |
Output is correct |
39 |
Correct |
28 ms |
5688 KB |
Output is correct |
40 |
Correct |
24 ms |
5608 KB |
Output is correct |
41 |
Correct |
23 ms |
5636 KB |
Output is correct |
42 |
Correct |
7 ms |
2764 KB |
Output is correct |
43 |
Correct |
9 ms |
2824 KB |
Output is correct |
44 |
Correct |
8 ms |
2892 KB |
Output is correct |
45 |
Correct |
28 ms |
8608 KB |
Output is correct |
46 |
Correct |
27 ms |
8648 KB |
Output is correct |
47 |
Correct |
57 ms |
13028 KB |
Output is correct |
48 |
Correct |
19 ms |
6216 KB |
Output is correct |
49 |
Correct |
18 ms |
5252 KB |
Output is correct |
50 |
Correct |
14 ms |
4808 KB |
Output is correct |
51 |
Correct |
65 ms |
8152 KB |
Output is correct |
52 |
Correct |
51 ms |
8640 KB |
Output is correct |
53 |
Correct |
33 ms |
5684 KB |
Output is correct |
54 |
Correct |
4 ms |
2924 KB |
Output is correct |
55 |
Correct |
6 ms |
3400 KB |
Output is correct |
56 |
Correct |
17 ms |
5116 KB |
Output is correct |
57 |
Correct |
41 ms |
11612 KB |
Output is correct |
58 |
Correct |
11 ms |
3652 KB |
Output is correct |
59 |
Correct |
12 ms |
4100 KB |
Output is correct |
60 |
Correct |
16 ms |
4680 KB |
Output is correct |
61 |
Correct |
16 ms |
4172 KB |
Output is correct |
62 |
Correct |
38 ms |
9280 KB |
Output is correct |
63 |
Correct |
93 ms |
26552 KB |
Output is correct |
64 |
Correct |
97 ms |
29756 KB |
Output is correct |
65 |
Correct |
122 ms |
39492 KB |
Output is correct |
66 |
Correct |
246 ms |
67700 KB |
Output is correct |
67 |
Correct |
242 ms |
67888 KB |
Output is correct |