#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxN = 3e4+10, OO = 0x3f3f3f3f;
int N, M;
vector<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});
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 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});
}
}
}
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);
}
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 (count(doges[to].begin(), doges[to].end(), doge)) break;
}
for (int to = i - doge, j = 1; to >= 0; to -= doge, j++){
adj[i].push_back({j, to});
if (count(doges[to].begin(), doges[to].end(), 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:62:27: warning: 'enB' may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | cout << dijkstra(stB, enB);
| ^
skyscraper.cpp:62:27: warning: 'stB' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1740 KB |
Output is correct |
2 |
Correct |
2 ms |
1740 KB |
Output is correct |
3 |
Correct |
1 ms |
1740 KB |
Output is correct |
4 |
Correct |
1 ms |
1740 KB |
Output is correct |
5 |
Correct |
1 ms |
1740 KB |
Output is correct |
6 |
Correct |
1 ms |
1740 KB |
Output is correct |
7 |
Correct |
2 ms |
1740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1740 KB |
Output is correct |
2 |
Correct |
1 ms |
1740 KB |
Output is correct |
3 |
Correct |
1 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
2 ms |
1740 KB |
Output is correct |
6 |
Correct |
2 ms |
1740 KB |
Output is correct |
7 |
Correct |
2 ms |
1740 KB |
Output is correct |
8 |
Correct |
2 ms |
1740 KB |
Output is correct |
9 |
Correct |
1 ms |
1740 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
2 ms |
1868 KB |
Output is correct |
12 |
Correct |
5 ms |
3912 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
1 ms |
1740 KB |
Output is correct |
3 |
Correct |
1 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
2 ms |
1740 KB |
Output is correct |
6 |
Correct |
1 ms |
1740 KB |
Output is correct |
7 |
Correct |
2 ms |
1740 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
1 ms |
1740 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
2 ms |
1868 KB |
Output is correct |
12 |
Correct |
6 ms |
3912 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
3 ms |
1996 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
3 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
3 ms |
1996 KB |
Output is correct |
25 |
Correct |
2 ms |
1868 KB |
Output is correct |
26 |
Correct |
70 ms |
34672 KB |
Output is correct |
27 |
Correct |
67 ms |
34628 KB |
Output is correct |
28 |
Correct |
2 ms |
2124 KB |
Output is correct |
29 |
Correct |
4 ms |
2508 KB |
Output is correct |
30 |
Correct |
3 ms |
2124 KB |
Output is correct |
31 |
Correct |
4 ms |
2252 KB |
Output is correct |
32 |
Correct |
3 ms |
2124 KB |
Output is correct |
33 |
Correct |
6 ms |
3148 KB |
Output is correct |
34 |
Correct |
5 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1740 KB |
Output is correct |
2 |
Correct |
1 ms |
1740 KB |
Output is correct |
3 |
Correct |
1 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
1 ms |
1792 KB |
Output is correct |
6 |
Correct |
1 ms |
1740 KB |
Output is correct |
7 |
Correct |
1 ms |
1740 KB |
Output is correct |
8 |
Correct |
2 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1740 KB |
Output is correct |
10 |
Correct |
2 ms |
1920 KB |
Output is correct |
11 |
Correct |
3 ms |
1868 KB |
Output is correct |
12 |
Correct |
7 ms |
3912 KB |
Output is correct |
13 |
Correct |
2 ms |
1920 KB |
Output is correct |
14 |
Correct |
3 ms |
1920 KB |
Output is correct |
15 |
Correct |
3 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
3 ms |
1996 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
3 ms |
1996 KB |
Output is correct |
25 |
Correct |
3 ms |
1868 KB |
Output is correct |
26 |
Correct |
73 ms |
34736 KB |
Output is correct |
27 |
Correct |
69 ms |
34712 KB |
Output is correct |
28 |
Correct |
3 ms |
2124 KB |
Output is correct |
29 |
Correct |
4 ms |
2508 KB |
Output is correct |
30 |
Correct |
2 ms |
2124 KB |
Output is correct |
31 |
Correct |
3 ms |
2252 KB |
Output is correct |
32 |
Correct |
3 ms |
2124 KB |
Output is correct |
33 |
Correct |
5 ms |
3148 KB |
Output is correct |
34 |
Correct |
6 ms |
3148 KB |
Output is correct |
35 |
Correct |
14 ms |
3020 KB |
Output is correct |
36 |
Correct |
5 ms |
2056 KB |
Output is correct |
37 |
Correct |
17 ms |
4044 KB |
Output is correct |
38 |
Correct |
16 ms |
3784 KB |
Output is correct |
39 |
Correct |
15 ms |
3736 KB |
Output is correct |
40 |
Correct |
14 ms |
3660 KB |
Output is correct |
41 |
Correct |
15 ms |
3880 KB |
Output is correct |
42 |
Runtime error |
398 ms |
262148 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1740 KB |
Output is correct |
2 |
Correct |
1 ms |
1740 KB |
Output is correct |
3 |
Correct |
1 ms |
1740 KB |
Output is correct |
4 |
Correct |
2 ms |
1740 KB |
Output is correct |
5 |
Correct |
1 ms |
1740 KB |
Output is correct |
6 |
Correct |
2 ms |
1740 KB |
Output is correct |
7 |
Correct |
1 ms |
1740 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
2 ms |
1740 KB |
Output is correct |
10 |
Correct |
2 ms |
1740 KB |
Output is correct |
11 |
Correct |
2 ms |
1868 KB |
Output is correct |
12 |
Correct |
5 ms |
3912 KB |
Output is correct |
13 |
Correct |
3 ms |
1868 KB |
Output is correct |
14 |
Correct |
2 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1996 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
3 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1740 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
4 ms |
1868 KB |
Output is correct |
24 |
Correct |
3 ms |
1996 KB |
Output is correct |
25 |
Correct |
3 ms |
1868 KB |
Output is correct |
26 |
Correct |
72 ms |
34656 KB |
Output is correct |
27 |
Correct |
67 ms |
34700 KB |
Output is correct |
28 |
Correct |
3 ms |
2124 KB |
Output is correct |
29 |
Correct |
4 ms |
2592 KB |
Output is correct |
30 |
Correct |
3 ms |
2124 KB |
Output is correct |
31 |
Correct |
4 ms |
2252 KB |
Output is correct |
32 |
Correct |
3 ms |
2124 KB |
Output is correct |
33 |
Correct |
7 ms |
3148 KB |
Output is correct |
34 |
Correct |
5 ms |
3104 KB |
Output is correct |
35 |
Correct |
14 ms |
2968 KB |
Output is correct |
36 |
Correct |
3 ms |
1996 KB |
Output is correct |
37 |
Correct |
12 ms |
4028 KB |
Output is correct |
38 |
Correct |
16 ms |
3908 KB |
Output is correct |
39 |
Correct |
15 ms |
3664 KB |
Output is correct |
40 |
Correct |
19 ms |
3680 KB |
Output is correct |
41 |
Correct |
16 ms |
3788 KB |
Output is correct |
42 |
Runtime error |
397 ms |
262148 KB |
Execution killed with signal 9 |
43 |
Halted |
0 ms |
0 KB |
- |